From: Alexey Charkov <alchark@gmail.com>
To: Alexey Charkov <alchark@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
Tony Prisk <linux@prisktech.co.nz>,
Alan Cox <alan@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
Greg Kroah-Hartman <gregkh@suse.de>,
Wentao Liang <vulab@iscas.ac.cn>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v2 4/6] serial: vt8500: Drop the port index bitmap
Date: Thu, 12 Nov 2026 19:33:12 +0400 [thread overview]
Message-ID: <20261112-vt8500-serial-cleanup-v2-4-36b258e0c0dd@gmail.com> (raw)
In-Reply-To: <20261112-vt8500-serial-cleanup-v2-0-36b258e0c0dd@gmail.com>
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@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-ca000721-4a5b-4d88-bdb8-7f1e438dc81e
Signed-off-by: Alexey Charkov <alchark@gmail.com>
---
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
next prev parent reply other threads:[~2026-11-12 15:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 15:33 [PATCH v2 0/6] serial: vt8500: Clean up the probe using devm and new serial core helpers Alexey Charkov
2026-11-12 15:33 ` [PATCH v2 1/6] serial: core: Add uart_console_port() Alexey Charkov
2026-11-12 15:33 ` [PATCH v2 2/6] serial: core: Allocate a free line for UART_LINE_AUTO ports Alexey Charkov
2026-11-12 15:33 ` [PATCH v2 3/6] serial: vt8500: Look up console ports with uart_console_port() Alexey Charkov
2026-11-12 15:33 ` Alexey Charkov [this message]
2026-11-12 15:33 ` [PATCH v2 5/6] serial: vt8500: Use devm_clk_get_enabled() Alexey Charkov
2026-11-12 15:33 ` [PATCH v2 6/6] serial: vt8500: Handle uart_add_one_port() failure Alexey Charkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112-vt8500-serial-cleanup-v2-4-36b258e0c0dd@gmail.com \
--to=alchark@gmail.com \
--cc=alan@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=gregkh@suse.de \
--cc=jirislaby@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux@prisktech.co.nz \
--cc=sashiko-bot@kernel.org \
--cc=vulab@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®