diff mbox series

[v2,7/7] serial: exar: fix: fix crash during shutdown if setup fails

Message ID 9af149b983592a7b8763132c64ca269909b4b8d3.1712863999.git.pnewman@connecttech.com
State Superseded
Headers show
Series serial: exar: add Connect Tech serial cards to Exar driver | expand

Commit Message

Parker Newman April 11, 2024, 8:25 p.m. UTC
From: Parker Newman <pnewman@connecttech.com>

If a port fails to register with serial8250_register_8250_port the
kernel can crash when shutting down or module removal.

This is because "priv->line[i]" will be set to a negative error code
andin the exar_pci_remove function serial8250_unregister_port is called
without checking if the "priv->line[i]" value is valid.

Signed-off-by: Parker Newman <pnewman@connecttech.com>
---
 drivers/tty/serial/8250/8250_exar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--
2.43.2
diff mbox series

Patch

diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/8250_exar.c
index d8425113a9f1..1c6343ed76e9 100644
--- a/drivers/tty/serial/8250/8250_exar.c
+++ b/drivers/tty/serial/8250/8250_exar.c
@@ -1675,7 +1675,8 @@  static void exar_pci_remove(struct pci_dev *pcidev)
 	unsigned int i;

 	for (i = 0; i < priv->nr; i++)
-		serial8250_unregister_port(priv->line[i]);
+		if (priv->line[i] >= 0)
+			serial8250_unregister_port(priv->line[i]);

 	/* Ensure that every init quirk is properly torn down */
 	if (priv->board->exit)