From: sashiko-bot@kernel.org
To: "Tapio Reijonen" <tapio.reijonen@vaisala.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: max310x: look at the port once after enabling its interrupts
Date: Fri, 20 Nov 2026 07:53:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-224662@kernel.org> (raw)
In-Reply-To: <20261120-max310x-startup-irq-status-v1-1-aee4e1416cf6@vaisala.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] serial: max310x: race between woken max310x_ist() and
max310x_shutdown()
--
commit cc3a091769281e06df6acf169978f695b85e9541
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>
serial: max310x: look at the port once after enabling its interrupts
This commit wakes the IRQ thread once at the end of max310x_startup() and
tracks ports to poll in s->poll_ports so characters received between FIFO
reset release and the initial status read are not stranded.
> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index de8a1f05cf30e..cdd1655c9f35c 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
[ ... ]
> @@ -1076,7 +1077,7 @@ static irqreturn_t max310x_ist(int irq, void *dev_id)
> WARN_ON_ONCE(regmap_read(s->regmap,
> MAX310X_GLOBALIRQ_REG, &val));
>
> - irq = val;
> + irq = val & ~xchg(&s->poll_ports, 0);
>
> for_each_clear_bit(port, &irq, s->devtype->nr) {
> done = false;
> @@ -1539,6 +1540,7 @@ static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios
>
> static int max310x_startup(struct uart_port *port)
> {
> + struct max310x_port *s = dev_get_drvdata(port->dev);
> struct max310x_one *one = to_max310x_port(port);
> unsigned int val;
>
> @@ -1595,11 +1597,19 @@ static int max310x_startup(struct uart_port *port)
> val = MAX310X_IRQ_RXEMPTY_BIT | MAX310X_IRQ_TXEMPTY_BIT;
> max310x_port_write(port, MAX310X_IRQEN_REG, val | MAX310X_IRQ_CTS_BIT);
>
> + /*
> + * A character received since the FIFO reset has lost its interrupt
> + * to the status read above: have the handler look at this port once.
> + */
> + set_bit(one - s->p, &s->poll_ports);
> + irq_wake_thread(port->irq, s);
> +
> return 0;
> }
>
> static void max310x_shutdown(struct uart_port *port)
> {
> + struct max310x_port *s = dev_get_drvdata(port->dev);
> struct max310x_one *one = to_max310x_port(port);
>
> /*
> @@ -1612,6 +1622,7 @@ static void max310x_shutdown(struct uart_port *port)
> scoped_guard(spinlock_irqsave, &port->lock)
> one->tx_teardown = true;
> max310x_port_write(port, MAX310X_IRQEN_REG, 0);
> + clear_bit(one - s->p, &s->poll_ports);
[Severity: High]
Can the IRQ thread woken by max310x_startup() run max310x_port_irq()
during or after max310x_shutdown(), re-arming one->tx_work after
cancel_work_sync(&one->tx_work)?
CPU0 CPU1 (IRQ thread)
max310x_startup()
set_bit(..., &s->poll_ports)
irq_wake_thread(port->irq, s)
max310x_ist()
xchg(&s->poll_ports, 0)
max310x_shutdown()
one->tx_teardown = true
max310x_port_write(..., IRQEN, 0)
clear_bit(..., &s->poll_ports)
...
/* pulses MAX310X_MODE2_FIFORST_BIT,
latching TXEMPTY in IRQSTS */
cancel_work_sync(&one->tx_work)
max310x_power(port, 0)
max310x_port_irq()
ists = ...IRQSTS_REG
schedule_work(&one->tx_work)
uart_shutdown()
uart_free_xmit_buf()
kfree(port.xmit_fifo)
max310x_tx_proc()
max310x_handle_tx()
<-- use-after-free on xmit_fifo
On multi-port chips, max310x_ist() consumes s->poll_ports with xchg()
before iterating over the ports, so clear_bit() in max310x_shutdown() does
not stop an already woken thread from visiting the port. On single-port
chips (s->devtype->nr == 1), the else branch in max310x_ist() ignores
s->poll_ports altogether and unconditionally calls max310x_port_irq(s, 0).
Because serial_core only calls synchronize_irq() in uart_port_shutdown()
after uport->ops->shutdown() returns, max310x_shutdown()'s FIFO reset can
latch MAX310X_IRQ_TXEMPTY_BIT and MAX310X_IRQ_CTS_BIT in
MAX310X_IRQSTS_REG, and max310x_port_irq() does not check
one->tx_teardown before scheduling one->tx_work.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-max310x-startup-irq-status-v1-1-aee4e1416cf6@vaisala.com?part=1
prev parent reply other threads:[~2026-11-20 7:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:39 [PATCH] serial: max310x: look at the port once after enabling its interrupts Tapio Reijonen
2026-11-20 7:53 ` sashiko-bot [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=sashiko-outbox-224662@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tapio.reijonen@vaisala.com \
/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