Re: [PATCH 1/3] serial: 8250_mxpcie: set the driver data before registering ports
Andy Shevchenko <[email protected]>
| Newsgroups | org.kernel.vger.linux-serial,org.kernel.vger.linux-kernel |
|---|---|
| Organization | Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo |
| Message-ID | <[email protected]> |
On Wed, Aug 19, 2026 at 05:07:35PM +0800, Crescent Hsieh wrote:
> 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.
> 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.
Either real ACPI node modifications or in lieu of fault injection we should not
rely on the property being absent.
> 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/[email protected]/
--
With Best Regards,
Andy Shevchenko