[PATCH v2 4/6] serial: vt8500: Drop the port index bitmap

From: Alexey Charkov

Date: Thu Nov 12 2026 - 10:58:47 EST


Stop reserving a line in the vt8500_ports_in_use bitmap before probe
acquires its resources: nothing ever clears the bit, so an early probe
failure strands the line, and a retry then fails with -EBUSY on an
aliased port or drifts to the next free index on an unaliased one.

Keep using an in-range "serial" alias, and otherwise let the serial core
pick a free line while it registers the port, so that a line is only
ever held by a registered port. That also stops an unaliased port from
taking the line of an aliased one that probes later.

Fixes: 4001130df1a7 ("serial: vt8500: Add devicetree support for vt8500-serial")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://sashiko.dev/#/bug/linux-ca000721-4a5b-4d88-bdb8-7f1e438dc81e
Signed-off-by: Alexey Charkov <alchark@xxxxxxxxx>
---
drivers/tty/serial/vt8500_serial.c | 37 +++++--------------------------------
1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
index 4abd4a8d5ef3..0c8ddd55f94d 100644
--- a/drivers/tty/serial/vt8500_serial.c
+++ b/drivers/tty/serial/vt8500_serial.c
@@ -90,7 +90,6 @@

#define VT8500_RECOMMENDED_CLK 12000000
#define VT8500_OVERSAMPLING_DIVISOR 13
-#define VT8500_MAX_PORTS 6

struct vt8500_port {
struct uart_port uart;
@@ -101,13 +100,6 @@ struct vt8500_port {
unsigned int vt8500_uart_flags;
};

-/*
- * we use this variable to keep track of which ports
- * have been allocated as we can't use pdev->id in
- * devicetree
- */
-static DECLARE_BITMAP(vt8500_ports_in_use, VT8500_MAX_PORTS);
-
static inline void vt8500_write(struct uart_port *port, unsigned int val,
unsigned int off)
{
@@ -606,29 +598,6 @@ static int vt8500_serial_probe(struct platform_device *pdev)
if (irq < 0)
return irq;

- if (np) {
- port = of_alias_get_id(np, "serial");
- if (port >= VT8500_MAX_PORTS)
- port = -1;
- } else {
- port = -1;
- }
-
- if (port < 0) {
- /* calculate the port id */
- port = find_first_zero_bit(vt8500_ports_in_use,
- VT8500_MAX_PORTS);
- }
-
- if (port >= VT8500_MAX_PORTS)
- return -ENODEV;
-
- /* reserve the port id */
- if (test_and_set_bit(port, vt8500_ports_in_use)) {
- /* port already in use - shouldn't really happen */
- return -EBUSY;
- }
-
vt8500_port = devm_kzalloc_obj(&pdev->dev, struct vt8500_port);
if (!vt8500_port)
return -ENOMEM;
@@ -661,7 +630,11 @@ static int vt8500_serial_probe(struct platform_device *pdev)
vt8500_port->uart.irq = irq;
vt8500_port->uart.fifosize = 16;
vt8500_port->uart.ops = &vt8500_uart_pops;
- vt8500_port->uart.line = port;
+ port = of_alias_get_id(np, "serial");
+ if (port >= 0 && port < vt8500_uart_driver.nr)
+ vt8500_port->uart.line = port;
+ else
+ vt8500_port->uart.line = UART_LINE_AUTO;
vt8500_port->uart.dev = &pdev->dev;
vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
vt8500_port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_VT8500_CONSOLE);

--
2.56.0