Skip to contentSkip to conversation

serial: altera_jtaguart: handle uart_add_one_port() failures

PATCH Superseded Myeonghun Pak 2 participants 2 messages Apr 28 – May 11

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: altera_jtaguart: handle uart_add_one_port() failures

altera_jtaguart_probe() maps the register window before registering the UART port, but it ignores failures from uart_add_one_port(). If port registration fails, probe still returns success and the mapping remains live until a later remove path that is not part of probe failure cleanup.

Return the uart_add_one_port() error and unmap the register window on that failure path.

Fixes 5bcd601049c6 ("serial: Add driver for the Altera JTAG UART")
---
 drivers/tty/serial/altera_jtaguart.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/tty/serial/altera_jtaguart.c +7 -1
index d47a62d1c9..15588b6dc3 100644
@@ -379,6 +379,7 @@ static int altera_jtaguart_probe(struct platform_device *pdev)
 	struct resource *res_mem;
 	int i = pdev->id;
 	int irq;
+	int ret;
 
 	/* -1 emphasizes that the platform must have one port, no .N suffix */
 	if (i == -1)
@@ -418,7 +419,12 @@ static int altera_jtaguart_probe(struct platform_device *pdev)
 	port->flags = UPF_BOOT_AUTOCONF;
 	port->dev = &pdev->dev;
 
-	uart_add_one_port(&altera_jtaguart_driver, port);
+	ret = uart_add_one_port(&altera_jtaguart_driver, port);
+	if (ret) {
+		iounmap(port->membase);
+		port->membase = NULL;
+		return ret;
+	}
 
 	return 0;
 }
Signature · 1 line
2.51.0
#1 lore raw
Quoted 29 lines · Myeonghun Pak

altera_jtaguart_probe() maps the register window before registering the UART port, but it ignores failures from uart_add_one_port(). If port registration fails, probe still returns success and the mapping remains live until a later remove path that is not part of probe failure cleanup.

Return the uart_add_one_port() error and unmap the register window on that failure path.

Fixes 5bcd601049c6 ("serial: Add driver for the Altera JTAG UART")
---
 drivers/tty/serial/altera_jtaguart.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/tty/serial/altera_jtaguart.c +1 -0
index d47a62d1c9..15588b6dc3 100644
@@ -379,6 +379,7 @@ static int altera_jtaguart_probe(struct platform_device *pdev)
 	struct resource *res_mem;
 	int i = pdev->id;
 	int irq;
+	int ret;
 
 	/* -1 emphasizes that the platform must have one port, no .N suffix */
 	if (i == -1)

drivers/tty/serial/altera_jtaguart.c static int altera_jtaguart_probe(struct platform_device *pdev) · line 425

Quoted 8 lines
drivers/tty/serial/altera_jtaguart.c +4 -1
@@ -418,7 +419,12 @@ static int altera_jtaguart_probe(struct platform_device *pdev)
 	port->flags = UPF_BOOT_AUTOCONF;
 	port->dev = &pdev->dev;
 
-	uart_add_one_port(&altera_jtaguart_driver, port);
+	ret = uart_add_one_port(&altera_jtaguart_driver, port);
+	if (ret) {
+		iounmap(port->membase);
+		port->membase = NULL;

Why is membase being set to NULL, that should not be needed, right?

How was this tested?

thanks,

greg k-h