On 11/17/21 23:15, Ruediger Willenberg wrote:
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 <r.willenberg@xxxxxxxxxxxxxx>
---
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