[PATCH 1/3] serial: 8250_mxpcie: set the driver data before registering ports
From: Linmao Li
Date: Tue Aug 18 2026 - 05:46:40 EST
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>
---
drivers/tty/serial/8250/8250_mxpcie.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index ce873fbd62e93..c0e3517d4e4ec 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -542,6 +542,8 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
mxpcie8250_init_board(pdev, priv);
+ pci_set_drvdata(pdev, priv);
+
up.port.dev = dev;
up.port.irq = pdev->irq;
up.port.uartclk = MOXA_PUART_BASE_BAUD * 16;
@@ -578,7 +580,6 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
}
priv->port[i].rx_trig_level = MOXA_PUART_RX_TRIG_DEFAULT;
}
- pci_set_drvdata(pdev, priv);
return 0;
}
--
2.25.1