drivers/tty/serial/max3100.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
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
On Tue, Apr 28, 2026 at 04:07:27PM +0900, 박명훈 wrote: > 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. NAK. Please, try to understand why we do like this and how important is to have at least some of the ports available (yes, I understand that this is not a robust solution, but it might help in the unlikely cases when some of the ports are failed to get instantiated. -- With Best Regards, Andy Shevchenko
© 2016 - 2026 Red Hat, Inc.