serial: uartlite: Move out-of-range port-numbers into ULITE_NR_UARTS range
Subsystems (2)
PATCH v3 1/1 serial: uartlite: Move out-of-range port-numbers into ULITE_NR_UARTS range
Find free uart_port struct in range 0 <= id < ULITE_NR_UARTS when the device tree port-number property is outside that range. This happens when there are other UART types in the system because the Xilinx device tree generator numbers all UARTs consecutively; as a result, not as many Uartlites as specified by the SERIAL_UARTLITE_NR_UARTS parameter could be successfully added.
---
Changes in v3:
- corrected indentation to strict formatting
Changes in v2:
- give KERN_NOTICE when changing the id,
with reference to the requested port-number
drivers/tty/serial/uartlite.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/tty/serial/uartlite.c +11 -4
@@ -631,15 +631,17 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq, {struct uart_port *port;int rc; +int oor_id =-1 ; -/* 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 ) { + oor_id = id;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 ; }
@@ -677,6 +679,11 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,return rc; } +if (oor_id >=0 ) +dev_notice (dev, +"assigned uartlite with device tree port-number=<%i> to %s%i\n" , + oor_id,ULITE_NAME , id); +return 0 ; }
Signature · 1 line
2.25.1
Quoted 48 lines · Ruediger Willenberg
Find free
uart_portstruct in range 0 <= id <ULITE_NR_UARTSwhen the device tree port-number property is outside that range. This happens when there are other UART types in the system because the Xilinx device tree generator numbers all UARTs consecutively; as a result, not as many Uartlites as specified by theSERIAL_UARTLITE_NR_UARTSparameter could be successfully added.Signed-off-by Ruediger Willenberg <[email protected]>---
Changes in v3:
- corrected indentation to strict formattingChanges in v2:
- giveKERN_NOTICEwhen changing the id,
with reference to the requested port-numberdrivers/tty/serial/uartlite.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)drivers/tty/serial/uartlite.c +6
-4@@ -631,15 +631,17 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq, {struct uart_port *port;int rc; +int oor_id =-1 ; -/* 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 ) { + oor_id = id;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 ; }@@ -677,6 +679,11 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,return rc;
drivers/tty/serial/uartlite.c static int ulite_assign(struct device *dev, int id, u32 base, int irq, · line 689
Quoted 10 lines
drivers/tty/serial/uartlite.c +5
-0} +if (oor_id >=0 ) +dev_notice (dev, +"assigned uartlite with device tree port-number=<%i> to %s%i\n" , + oor_id,ULITE_NAME , id); +return 0 ; }
I will wait for Greg to comment it first.
https://lore.kernel.org/all/[email protected]/
As I said before this patch can cause issues when you will have mix of serial IPs with and without serial alias that IP without serial alias can take ID to IP which has it. (All ports without optional port-number property).
Thanks,
Michal
Greg KH
maintainerQuoted 6 lines · Ruediger Willenberg
Find free
uart_portstruct in range 0 <= id <ULITE_NR_UARTSwhen the device tree port-number property is outside that range. This happens when there are other UART types in the system because the Xilinx device tree generator numbers all UARTs consecutively; as a result, not as many Uartlites as specified by theSERIAL_UARTLITE_NR_UARTSparameter could be successfully added.
Ick. Please just remove that build option entirely, this should just dynamically allocate new devices based on what is in the system.
The driver should not care at build time about this.
thanks,
greg k-h
Am 24.11.2021 um 11:08 schrieb Greg KH:
Quoted 8 lines · Ruediger Willenberg
Quoted 6 lines
Find free
uart_portstruct in range 0 <= id <ULITE_NR_UARTSwhen the device tree port-number property is outside that range. This happens when there are other UART types in the system because the Xilinx device tree generator numbers all UARTs consecutively; as a result, not as many Uartlites as specified by theSERIAL_UARTLITE_NR_UARTSparameter could be successfully added.
Quoted 5 lines
Ick. Please just remove that build option entirely, this should just dynamically allocate new devices based on what is in the system.
The driver should not care at build time about this.
Fully agree removing SERIAL_UARTLITE_NR_UARTS and making allocation dynamic is best. Please briefly advise on how to best handle the following resulting issue:
In serial_core.c the following check occurs:
int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) {
...
if (uport->line >= drv->nr) return -EINVAL;
To not let this fail on registering a legit uartlite port, should we
* Set ulite_uart_driver.nr = INT_MAX before registering the driver
* Adjust ulite_uart_driver.nr when adding or removing a port (surely with lock, but still smells)
* do something blindingly obvious I'm missing?
Thank you,
Ruediger
Greg KH
maintainerQuoted 24 lines · Ruediger Willenberg
Am 24.11.2021 um 11:08 schrieb Greg KH:
Quoted 8 lines · Ruediger Willenberg
Quoted 6 lines
Find free
uart_portstruct in range 0 <= id <ULITE_NR_UARTSwhen the device tree port-number property is outside that range. This happens when there are other UART types in the system because the Xilinx device tree generator numbers all UARTs consecutively; as a result, not as many Uartlites as specified by theSERIAL_UARTLITE_NR_UARTSparameter could be successfully added.Quoted 5 lines
Ick. Please just remove that build option entirely, this should just dynamically allocate new devices based on what is in the system.
The driver should not care at build time about this.
Fully agree removing
SERIAL_UARTLITE_NR_UARTSand making allocation dynamic is best.
Please briefly advise on how to best handle the following resulting issue:In
serial_core.cthe following check occurs:int
uart_add_one_port(struct uart_driver *drv, struct uart_port *uport){
...
Quoted 7 lines
if (uport->line >= drv->nr) return -EINVAL;To not let this fail on registering a legit uartlite port, should we
* Set ulite_uart_driver.nr =
INT_MAXbefore registering the driver
Or just 256, be kind :)
Quoted 2 lines
* Adjust ulite_uart_driver.nr when adding or removing a port (surely with lock, but still smells)
Why do you need to change this when adding/removing a port?
Quoted 1 line
* do something blindingly obvious I'm missing?
I do not know, sorry, try it and see!
greg k-h