Re: [PATCH] serial: uartlite: Move out-of-range port-numbers into ULITE_NR_UARTS range
From: Ruediger Willenberg <hidden>
Date: 2021-11-18 21:16:26
Am 18.11.2021 um 09:34 schrieb Michal Simek:
On 11/17/21 23:15, Ruediger Willenberg wrote:quoted
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; }Don't you want to also inform user about it? They can expect that serial10 is going to be ttyUL10 but if ULITE_NR_UARTS is less you will get different number and user will have no idea why. Thanks, Michal
Good catch, thanks! Will add a dev_notice() and repost. -Ruediger