FAILED: patch "[PATCH] serial: 8250_exar: store the GPIO platform device in struct exar8250" failed to apply to 6.6-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 33d337816e00994daaf670243186d9e537ee090d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 33d337816e00994daaf670243186d9e537ee090d Mon Sep 17 00:00:00 2001
From: "Jiri Slaby (SUSE)" <[email protected]>
Date: Tue, 13 Oct 2026 08:48:48 +0200
Subject: [PATCH] serial: 8250_exar: store the GPIO platform device in struct
exar8250
The GPIO platform device is registered via platform->register_gpio() when port 0 is being set up. It is stored to port->port.private_data of the on-stack uart template (and from there it is copied into every registered port). pci_xr17v35x_exit() then fetches it back by serial8250_get_port(priv->line[0]).
But port 0 does not have to exist at that point. If serial8250_register_8250_port() fails for port 0, priv->line[0] holds a negative error code. The probe still succeeds (it only breaks the loop), so on unbind, priv->line[0] (a negative value) is passed to serial8250_get_port(). The GPIO device is never unregistered and a bogus port is accessed.
The same problem would also occur after the planned conversion of serial8250_register_8250_port() to return a uart port instead of a line. As Sashiko pointed out in that case:
If board->setup() fails for the first port (i=0) in exar_pci_probe(), priv->uport[0] remains NULL. If serial8250_register_8250_port() fails, it returns an ERR_PTR. In either case, the loop breaks and probe returns success. When the device is later unbound, pci_xr17v35x_exit() unconditionally passes priv->uport[0] to platform->unregister_gpio(), which will dereference it without checking for validity.
The GPIO device belongs to the PCI device, not to any particular port. So store it in a new struct exar8250::gpio member. Pass priv to both ->register_gpio() and ->unregister_gpio(), so that pci_xr17v35x_exit() does not need to look up any port at all.
--- drivers/tty/serial/8250/8250_exar.c | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/tty/serial/8250/8250_exar.c +18 -18
@@ -231,8 +231,9 @@ struct exar8250_platform {int (*rs485_config)(struct uart_port *port,struct ktermios *termios,struct serial_rs485 *rs485);const struct serial_rs485 *rs485_supported; -int (*register_gpio)(struct pci_dev *pcidev,struct uart_8250_port *port); -void (*unregister_gpio)(struct uart_8250_port *port); +int (*register_gpio)(struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port); +void (*unregister_gpio)(struct exar8250 *priv); };/**
@@ -256,6 +257,7 @@ struct exar8250 {struct exar8250_board *board;struct eeprom_93cx6 eeprom;void __iomem *virt; +struct platform_device *gpio;int line[]; };
@@ -1167,22 +1169,21 @@ static const struct software_node exar_gpio_node = { .properties = exar_gpio_properties, }; -static int xr17v35x_register_gpio (struct pci_dev *pcidev,struct uart_8250_port *port) +static int xr17v35x_register_gpio (struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port) {if (pcidev->vendor ==PCI_VENDOR_ID_EXAR ) - port->port.private_data = -__xr17v35x_register_gpio (pcidev, &exar_gpio_node); + priv->gpio =__xr17v35x_register_gpio (pcidev, &exar_gpio_node);return 0 ; } -static void xr17v35x_unregister_gpio (struct uart_8250_port *port) +static void xr17v35x_unregister_gpio (struct exar8250 *priv) { -if (!port->port.private_data) -return ; - -__xr17v35x_unregister_gpio (port->port.private_data); - port->port.private_data =NULL ; +if (priv->gpio) { +__xr17v35x_unregister_gpio (priv->gpio); + priv->gpio =NULL ; + } } static int sealevel_rs485_config(struct uart_port *port, struct ktermios *termios,
@@ -1279,8 +1280,9 @@ static const struct software_node iot2040_gpio_node = { .properties = iot2040_gpio_properties, }; -static int iot2040_register_gpio (struct pci_dev *pcidev, -struct uart_8250_port *port) +static int iot2040_register_gpio (struct exar8250 *priv, +struct pci_dev *pcidev, +struct uart_8250_port *port) {u8 __iomem *p = port->port.membase;
@@ -1289,8 +1291,7 @@ static int iot2040_register_gpio(struct pci_dev *pcidev,writeb (IOT2040_UARTS_ENABLE , p +UART_EXAR_MPIOLVL_15_8 );writeb (IOT2040_UARTS_GPIO_HI_MODE , p +UART_EXAR_MPIOSEL_15_8 ); - port->port.private_data = -__xr17v35x_register_gpio (pcidev, &iot2040_gpio_node); + priv->gpio =__xr17v35x_register_gpio (pcidev, &iot2040_gpio_node);return 0 ; }
@@ -1367,7 +1368,7 @@ pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,/* Setup Multipurpose Input/Output pins. */ setup_gpio (pcidev, p); - ret = platform->register_gpio (pcidev, port); + ret = platform->register_gpio (priv, pcidev, port); }return ret;
@@ -1377,9 +1378,8 @@ static void pci_xr17v35x_exit(struct pci_dev *pcidev) {const struct exar8250_platform *platform =exar_get_platform ();struct exar8250 *priv =pci_get_drvdata (pcidev); -struct uart_8250_port *port =serial8250_get_port (priv->line[0 ]); - platform->unregister_gpio (port); + platform->unregister_gpio (priv); }static inline void exar_misc_clear (struct exar8250 *priv)
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/4 serial: 8250_exar: Clear interrupts before registering handler
From: Andy Shevchenko <[email protected]>
[ Upstream commit 5bc430afeba5d5101765c1f1a4437a90218b00b9 ]
While now there is no issue if IRQ is fired before we clearing the interrupts as the handler does the same, but strictly speaking it might be problematic if IRQ handler wants to do something more.
Move clearing interrupt code to be called before registering the IRQ handler.
Stable-dep-of: 33d337816e00 ("serial: 8250_exar: store the GPIO platform device in struct exar8250")
--- drivers/tty/serial/8250/8250_exar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_exar.c +3 -3
@@ -722,14 +722,14 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) uart.port.irq =pci_irq_vector (pcidev,0 ); uart.port.dev = &pcidev->dev; +/* Clear interrupts */ +exar_misc_clear (priv); + rc =devm_request_irq (&pcidev->dev, uart.port.irq, exar_misc_handler,IRQF_SHARED ,"exar_uart" , priv);if (rc)return rc; -/* Clear interrupts */ -exar_misc_clear (priv); -for (i =0 ; i < nr_ports && i < maxnr; i++) { rc = board->setup (priv, pcidev, &uart, i);if (rc) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 serial: exar: add optional board_init function
From: Parker Newman <[email protected]>
[ Upstream commit 393b520a99b21d9ec6d4bb32e7c05bbb4f6dc777 ]
Add an optional "board_init()" function pointer to struct exar8250_board which is called once during probe prior to setting up the ports. It will be used in subsequent patches of this series.
Stable-dep-of: 33d337816e00 ("serial: 8250_exar: store the GPIO platform device in struct exar8250")
--- drivers/tty/serial/8250/8250_exar.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_exar.c +12 -1
@@ -177,12 +177,14 @@ struct exar8250_platform {* struct exar8250_board - board information * @num_ports: number of serial ports * @reg_shift: describes UART register mapping in PCI memory -* @setup: quirk run at ->probe() stage +* @board_init: quirk run once at ->probe() stage before setting up ports +* @setup: quirk run at ->probe() stage for each port * @exit: quirk run at ->remove() stage */ struct exar8250_board {unsigned int num_ports;unsigned int reg_shift; +int (*board_init)(struct exar8250 *priv,struct pci_dev *pcidev);int (*setup)(struct exar8250 *,struct pci_dev *,struct uart_8250_port *,int );void (*exit)(struct pci_dev *pcidev);
@@ -730,6 +732,15 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)if (rc)return rc; +if (board->board_init) { + rc = board->board_init (priv, pcidev); +if (rc) { +dev_err_probe (&pcidev->dev, rc, +"failed to init serial board\n" ); +return rc; + } + } +for (i =0 ; i < nr_ports && i < maxnr; i++) { rc = board->setup (priv, pcidev, &uart, i);if (rc) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 serial: exar: fix checkpach warnings
In reply to Sasha LevinFrom: Parker Newman <[email protected]>
[ Upstream commit c6795fbffc4547b40933ec368200bd4926a41b44 ]
-Fix several "missing identifier name" warnings from checkpatch in struct exar8250_platform and struct exar8250_board. Example:
WARNING: function definition argument <arg> should also have an identifier name
- Fix space before tab warning from checkpatch:
WARNING: please, no space before tabs
+ * 0^I^I2 ^IMode bit 0$
Stable-dep-of: 33d337816e00 ("serial: 8250_exar: store the GPIO platform device in struct exar8250")
--- drivers/tty/serial/8250/8250_exar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/tty/serial/8250/8250_exar.c +5 -5
@@ -133,7 +133,7 @@* * MPIO Port Function * ---- ---- -------- -* 0 2 Mode bit 0 +* 0 2 Mode bit 0 * 1 2 Mode bit 1 * 2 2 Terminate bus * 3 - <reserved>
@@ -169,8 +169,8 @@ struct exar8250_platform {int (*rs485_config)(struct uart_port *port,struct ktermios *termios,struct serial_rs485 *rs485);const struct serial_rs485 *rs485_supported; -int (*register_gpio)(struct pci_dev *,struct uart_8250_port *); -void (*unregister_gpio)(struct uart_8250_port *); +int (*register_gpio)(struct pci_dev *pcidev,struct uart_8250_port *port); +void (*unregister_gpio)(struct uart_8250_port *port); };/**
@@ -185,8 +185,8 @@ struct exar8250_board {unsigned int num_ports;unsigned int reg_shift;int (*board_init)(struct exar8250 *priv,struct pci_dev *pcidev); -int (*setup)(struct exar8250 *,struct pci_dev *, -struct uart_8250_port *,int ); +int (*setup)(struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port,int idx);void (*exit)(struct pci_dev *pcidev); };
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 serial: 8250_exar: store the GPIO platform device in struct exar8250
In reply to Sasha LevinFrom: "Jiri Slaby (SUSE)" <[email protected]>
[ Upstream commit 33d337816e00994daaf670243186d9e537ee090d ]
The GPIO platform device is registered via platform->register_gpio() when port 0 is being set up. It is stored to port->port.private_data of the on-stack uart template (and from there it is copied into every registered port). pci_xr17v35x_exit() then fetches it back by serial8250_get_port(priv->line[0]).
But port 0 does not have to exist at that point. If serial8250_register_8250_port() fails for port 0, priv->line[0] holds a negative error code. The probe still succeeds (it only breaks the loop), so on unbind, priv->line[0] (a negative value) is passed to serial8250_get_port(). The GPIO device is never unregistered and a bogus port is accessed.
The same problem would also occur after the planned conversion of serial8250_register_8250_port() to return a uart port instead of a line. As Sashiko pointed out in that case:
If board->setup() fails for the first port (i=0) in exar_pci_probe(), priv->uport[0] remains NULL. If serial8250_register_8250_port() fails, it returns an ERR_PTR. In either case, the loop breaks and probe returns success. When the device is later unbound, pci_xr17v35x_exit() unconditionally passes priv->uport[0] to platform->unregister_gpio(), which will dereference it without checking for validity.
The GPIO device belongs to the PCI device, not to any particular port. So store it in a new struct exar8250::gpio member. Pass priv to both ->register_gpio() and ->unregister_gpio(), so that pci_xr17v35x_exit() does not need to look up any port at all.
--- drivers/tty/serial/8250/8250_exar.c | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/tty/serial/8250/8250_exar.c +18 -18
@@ -169,8 +169,9 @@ struct exar8250_platform {int (*rs485_config)(struct uart_port *port,struct ktermios *termios,struct serial_rs485 *rs485);const struct serial_rs485 *rs485_supported; -int (*register_gpio)(struct pci_dev *pcidev,struct uart_8250_port *port); -void (*unregister_gpio)(struct uart_8250_port *port); +int (*register_gpio)(struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port); +void (*unregister_gpio)(struct exar8250 *priv); };/**
@@ -194,6 +195,7 @@ struct exar8250 {unsigned int nr;struct exar8250_board *board;void __iomem *virt; +struct platform_device *gpio;int line[]; };
@@ -452,22 +454,21 @@ static const struct software_node exar_gpio_node = { .properties = exar_gpio_properties, }; -static int xr17v35x_register_gpio (struct pci_dev *pcidev,struct uart_8250_port *port) +static int xr17v35x_register_gpio (struct exar8250 *priv,struct pci_dev *pcidev, +struct uart_8250_port *port) {if (pcidev->vendor ==PCI_VENDOR_ID_EXAR ) - port->port.private_data = -__xr17v35x_register_gpio (pcidev, &exar_gpio_node); + priv->gpio =__xr17v35x_register_gpio (pcidev, &exar_gpio_node);return 0 ; } -static void xr17v35x_unregister_gpio (struct uart_8250_port *port) +static void xr17v35x_unregister_gpio (struct exar8250 *priv) { -if (!port->port.private_data) -return ; - -__xr17v35x_unregister_gpio (port->port.private_data); - port->port.private_data =NULL ; +if (priv->gpio) { +__xr17v35x_unregister_gpio (priv->gpio); + priv->gpio =NULL ; + } } static int generic_rs485_config(struct uart_port *port, struct ktermios *termios,
@@ -550,8 +551,9 @@ static const struct software_node iot2040_gpio_node = { .properties = iot2040_gpio_properties, }; -static int iot2040_register_gpio (struct pci_dev *pcidev, -struct uart_8250_port *port) +static int iot2040_register_gpio (struct exar8250 *priv, +struct pci_dev *pcidev, +struct uart_8250_port *port) {u8 __iomem *p = port->port.membase;
@@ -560,8 +562,7 @@ static int iot2040_register_gpio(struct pci_dev *pcidev,writeb (IOT2040_UARTS_ENABLE , p +UART_EXAR_MPIOLVL_15_8 );writeb (IOT2040_UARTS_GPIO_HI_MODE , p +UART_EXAR_MPIOSEL_15_8 ); - port->port.private_data = -__xr17v35x_register_gpio (pcidev, &iot2040_gpio_node); + priv->gpio =__xr17v35x_register_gpio (pcidev, &iot2040_gpio_node);return 0 ; }
@@ -635,7 +636,7 @@ pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,/* Setup Multipurpose Input/Output pins. */ setup_gpio (pcidev, p); - ret = platform->register_gpio (pcidev, port); + ret = platform->register_gpio (priv, pcidev, port); }return ret;
@@ -645,9 +646,8 @@ static void pci_xr17v35x_exit(struct pci_dev *pcidev) {const struct exar8250_platform *platform =exar_get_platform ();struct exar8250 *priv =pci_get_drvdata (pcidev); -struct uart_8250_port *port =serial8250_get_port (priv->line[0 ]); - platform->unregister_gpio (port); + platform->unregister_gpio (priv); }static inline void exar_misc_clear (struct exar8250 *priv)
Signature · 1 line
2.53.0