Thread (3 messages) 3 messages, 2 authors, 2021-11-18
STALE1707d

[PATCH] serial: uartlite: Move out-of-range port-numbers into ULITE_NR_UARTS range

From: Ruediger Willenberg <hidden>
Date: 2021-11-17 22:16:26
Subsystem: the rest, tty layer and serial drivers, xilinx uartlite serial driver · Maintainers: Linus Torvalds, Greg Kroah-Hartman, Jiri Slaby, Peter Korsgaard

Find free uart_port struct in range 0 <= id < ULITE_NR_UARTS when
the device tree port-number property is outside that range. This
can happen because the Xilinx device tree generator does not start
enumerating Uartlites at 0 when there are PS-UARTs or AXI 16550A
UARTs in the system; it then enumerates all UARTs consecutively
despite them having separate drivers with separate structures.
This has become more problematic since the Kconfig property
SERIAL_UARTLITE_NR_UARTS enables precise allocation of uart_port
structs, which can't be used if the port-number doesn't start at 0

Signed-off-by: Ruediger Willenberg <redacted>
---
 drivers/tty/serial/uartlite.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index d3d9566e5dbd..546eecdb6033 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -632,14 +632,14 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
 	struct uart_port *port;
 	int rc;
 
-	/* if id = -1; then scan for a free id and use that */
-	if (id < 0) {
+	/* if id -1 or out of range; then scan for a free id and use that */
+	if (id < 0 || id >= ULITE_NR_UARTS) {
 		for (id = 0; id < ULITE_NR_UARTS; id++)
 			if (ulite_ports[id].mapbase == 0)
 				break;
 	}
-	if (id < 0 || id >= ULITE_NR_UARTS) {
-		dev_err(dev, "%s%i too large\n", ULITE_NAME, id);
+	if (id == ULITE_NR_UARTS) {
+		dev_err(dev, "maximum number of %s assigned\n", ULITE_NAME);
 		return -EINVAL;
 	}
 
-- 
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help