Re: [PATCH v2 2/3] serial: 8250_mxpcie: only unregister the ports that were registered

From: Andy Shevchenko

Date: Tue Sep 01 2026 - 05:06:06 EST


On Tue, Sep 01, 2026 at 12:15:18PM +0800, Linmao Li wrote:
> When serial8250_register_8250_port() fails the loop stops and the probe
> keeps the ports registered so far, like pciserial_init_ports() in
> 8250_pci.c this driver was split from. What the split lost is that
> function's priv->nr: mxpcie8250_remove() walks all num_ports entries,
> but the ones the loop never reached keep the zero devm_kzalloc() left
> there, and the one that failed keeps a negative error code.
>
> serial8250_unregister_port() checks neither, so removal unregisters
> line 0 - a port this driver does not own - and indexes
> serial8250_ports[] with a negative line number.
>
> Record how many ports were registered and unregister only those.

...

> struct mxpcie8250 {

> unsigned int supp_rs;
> unsigned int num_ports;
> + unsigned int nr; /* ports actually registered */

I would make it indented with the below comments.
But no need to resend for this. It's not critical at all.

> void __iomem *bar1_base; /* UART registers (MMIO) */
> void __iomem *bar2_base; /* UIR / GPIO / CPLD (IO) */
> struct mxpcie8250_port port[] __counted_by(num_ports);

--
With Best Regards,
Andy Shevchenko