public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: max3100: unwind port allocation on add failure
@ 2026-04-28  7:07 박명훈
  2026-04-28  7:33 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: 박명훈 @ 2026-04-28  7:07 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Ijae Kim, Myeonghun Pak

From: Myeonghun Pak <mhun512@gmail.com>

max3100_probe() reports errors from uart_add_one_port(), but then
continues initialization and returns success. The device is left with
per-port state in max3100s[] even though serial core did not add the
port.

Return the uart_add_one_port() error instead. Free the per-port state
and, when no other chips remain, unregister the UART driver that probe
registered.

Fixes: 7831d56b0a35 ("tty: MAX3100")
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 drivers/tty/serial/max3100.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 475b0a6efc..83a9db1819 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -732,13 +732,31 @@ static int max3100_probe(struct spi_device *spi)
 	device_property_read_u32(dev, "clock-frequency", &max3100s[i]->port.uartclk);
 
 	retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port);
-	if (retval < 0)
+	if (retval < 0) {
 		dev_err_probe(dev, retval, "uart_add_one_port failed for line %d\n", i);
+		goto err_free_port;
+	}
 
 	/* set shutdown mode to save power. Will be woken-up on open */
 	max3100_sr(max3100s[i], MAX3100_WC | MAX3100_SHDN, &rx);
 	mutex_unlock(&max3100s_lock);
 	return 0;
+
+err_free_port:
+	kfree(max3100s[i]);
+	max3100s[i] = NULL;
+
+	for (i = 0; i < MAX_MAX3100; i++)
+		if (max3100s[i])
+			break;
+
+	if (i == MAX_MAX3100) {
+		uart_unregister_driver(&max3100_uart_driver);
+		uart_driver_registered = 0;
+	}
+
+	mutex_unlock(&max3100s_lock);
+	return retval;
 }
 
 static void max3100_remove(struct spi_device *spi)
-- 
2.50.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-28  7:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28  7:07 [PATCH] serial: max3100: unwind port allocation on add failure 박명훈
2026-04-28  7:33 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox