Re: [PATCH 2/3] serial: 8250_mxpcie: fail the probe when a port cannot be registered

From: Linmao Li

Date: Tue Aug 18 2026 - 21:43:53 EST



在 2026/8/18 21:19, Andy Shevchenko 写道:
On Tue, Aug 18, 2026 at 05:39:17PM +0800, Linmao Li wrote:
When serial8250_register_8250_port() fails the loop only breaks out and
the probe still returns success. The entries it did not reach keep the
zero devm_kzalloc() left there, and the entry that failed keeps a
negative error code.

mxpcie8250_remove() then feeds all of them to
serial8250_unregister_port(), which checks neither: line 0 unregisters a
port this driver does not own, and the negative line indexes
serial8250_ports[] out of bounds.

Fail the probe instead, unregistering the ports registered so far.
This is behavioural difference. Before it was "register as much ports as we
can", now "don't register even a single one". If one of those UARTs worked in
the previous case for whatever reason, this patch will break that.
You are right, and 8250_pci.c - which this driver was split out of - is
explicit about it: pciserial_init_ports() breaks out of the loop on the
first failure, but returns the ports it did register and records how many
in priv->nr, which is all pciserial_detach_ports() then walks.

So what the split lost is that counter, not the "keep what works"
behaviour. mxpcie8250_remove() walks all num_ports entries, so it hands
serial8250_unregister_port() a line 0 for every entry the loop never
reached - a port this driver does not own - and a negative line for the
one that failed.

v2 keeps the partial registration and restores the counter only.


Thanks,
Linmao