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 4/4] serial: vt8500: Drop the port index bitmap
Date: Wed, 11 Nov 2026 23:19:19 +0400 [thread overview]
Message-ID: <20261111-vt8500-serial-cleanup-v1-4-b33594a25f87@gmail.com> (raw)
In-Reply-To: <20261111-vt8500-serial-cleanup-v1-0-b33594a25f87@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.
Pick the line from the serial core state instead and let
uart_add_one_port() claim it, as the core already refuses a taken line
under its port mutex. Rely on that for concurrent probes too, so that a
racing probe fails cleanly with no driver state to roll back.
Keep the allocation policy as is: honour an in-range "serial" alias,
otherwise fall back to the first free line.
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 | 35 +++++++----------------------------
1 file changed, 7 insertions(+), 28 deletions(-)
diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
index 7c7b4beb51fd..f9858f10b5db 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)
{
@@ -611,27 +603,14 @@ 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;
+ port = np ? of_alias_get_id(np, "serial") : -ENODEV;
+ if (port < 0 || port >= vt8500_uart_driver.nr) {
+ for (port = 0; port < vt8500_uart_driver.nr; port++)
+ if (!vt8500_uart_driver.state[port].uart_port)
+ break;
- /* reserve the port id */
- if (test_and_set_bit(port, vt8500_ports_in_use)) {
- /* port already in use - shouldn't really happen */
- return -EBUSY;
+ if (port == vt8500_uart_driver.nr)
+ return -ENODEV;
}
vt8500_port = devm_kzalloc_obj(&pdev->dev, struct vt8500_port);
--
2.56.0
prev parent reply other threads:[~2026-11-11 19:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 19:19 [PATCH 0/4] serial: vt8500: Clean up the probe Alexey Charkov
2026-11-11 19:19 ` [PATCH 1/4] serial: vt8500: Find console ports in the serial core state Alexey Charkov
2026-11-11 19:19 ` [PATCH 2/4] serial: vt8500: Use devm_clk_get_enabled() Alexey Charkov
2026-11-11 19:19 ` [PATCH 3/4] serial: vt8500: Handle uart_add_one_port() failure Alexey Charkov
2026-11-11 19:19 ` Alexey Charkov [this message]
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=20261111-vt8500-serial-cleanup-v1-4-b33594a25f87@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®