Re: [PATCH 1/3] serial: 8250_mxpcie: set the driver data before registering ports

From: Crescent Hsieh

Date: Wed Aug 19 2026 - 05:08:42 EST


On Tue, Aug 18, 2026 at 05:39:16PM +0800, Linmao Li wrote:
> mxpcie8250_rs485_config() looks the board up with dev_get_drvdata() on
> the PCI device, but pci_set_drvdata() only runs after the registration
> loop. Where mxpcie8250_setup_port() presets rs485.flags to
> SER_RS485_ENABLED, uart_configure_port() calls ->rs485_config() from
> inside serial8250_register_8250_port(), and the callback dereferences a
> NULL board pointer.
>
> Publish the driver data before the first port is registered.
>
> Fixes: d21a1509c623 ("serial: 8250_mxpcie: support serial interface mode switching")
> Signed-off-by: Linmao Li <lilinmao@xxxxxxxxxx>

Hi,

Thanks for pointing this out.

I tried to reproduce the NULL pointer dereference with a CP-134EL-A on
an ACPI x86 system, but the callback was not reached during port
registration.

The driver initially sets the RS485 flags to 0x201
(SER_RS485_ENABLED | SER_RS485_MODE_RS422) and directly programs the
hardware interface for RS422. However, uart_get_rs485_mode() finds an
ACPI firmware node and changes the flags to 0x202 because the node does
not provide the linux,rs485-enabled-at-boot-time property.

uart_configure_port() subsequently calls uart_rs485_config(), but the
latter returns without calling mxpcie8250_rs485_config() because
SER_RS485_ENABLED is no longer set. Therefore, the NULL driver-data
pointer is not dereferenced on this system.

This also leaves the software state inconsistent with the hardware
after initialization. The hardware is configured for RS422, while
TIOCGRS485 reports SER_RS485_MODE_RS422 without SER_RS485_ENABLED.

I also reviewed commit 6974711cf770 ("serial: Keep rs485 settings for
devices without firmware node") and its review discussion [1]. That
change preserves driver-provided defaults when no firmware node exists.
In this case, however, the PCI device has a generic ACPI firmware node
without any RS485 properties.

The driver-data ordering change still looks correct to me because
SER_RS485_ENABLED is preserved on systems without a firmware node,
allowing mxpcie8250_rs485_config() to be called during port
registration. The case where an ACPI firmware node exists but provides
no RS485 properties appears to be a separate issue that also needs to
be addressed.

[1]
https://lore.kernel.org/all/20251023151229.11774-2-gerhard@xxxxxxxxxxxxxxxxxxxxx/

---
Thanks,
Crescent Hsieh