All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes
@ 2026-11-20  7:33 Tapio Reijonen
  2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-20  7:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan, Andy Shevchenko
  Cc: linux-serial, linux-kernel, Hugo Villeneuve, stable,
	Tapio Reijonen

Three fixes for problems that predate the RS485 software-delay series
and were raised during its review: port removal cancelled the per-port
work before the IRQ was freed and the port unregistered, a failed probe
left queued work behind and could mark another chip's port line as
free, and the CTS change was reported to serial core without the port
lock.

Tested on two MAX14830, four UARTs each on SPI, on an ARMv7 single-core
board, on tty-next from the 7.4 merge window with the board support on
top, all ports in RS-485 mode and one switched to RS-232 where a test
needs it. For the teardown tests the kernel ran with PROVE_LOCKING,
DEBUG_OBJECTS, DEBUG_ATOMIC_SLEEP, DEBUG_KMEMLEAK and init_on_free, a
500 ms delay was added to the work items so that a late one is still
running when the port memory is freed, and the probe failures were
injected through test-only module parameters.

The first fix was reproduced that way: unbinding the chip with a port
open made md_work, queued by the hangup, run on the freed port and
oops; with the fix the unbind waits for it, also while the other chip
carries traffic. For the second, a failed IRQ request after all four
ports were registered waits for the rs_work items queued by the RS-485
configuration before probe returns, and a port registration failure on
the second chip leaves the first chip's port 0 in place; a rebind
brings every port back under its original number. The third was checked
with the chip's internal loopback feeding RTS to CTS under
PROVE_LOCKING.

The series then ran through a scripted campaign on the same board:
unbinding a chip under open ports with blocked readers, TIOCMIWAIT
waiters and a draining close pending (80 cycles), with sixteen
processes opening and closing its ports nonstop (100 cycles), and with
verified loopback traffic on the other chip (four one-hour runs and a
two-hour soak, 1250 cycles, no kmemleak report, Slab growth under
1 MB); the probe failure injections with openers racing the node names;
lockdep stayed enabled throughout and no warning, hung task or stuck
process was recorded. Two bugs outside this series surfaced in that
campaign and are fixed separately, this series does not depend on
either: serial core's port removal waited for the port's references
with the port mutex held, against which tcdrain() on the hung-up port
deadlocks, and the driver's TX work advanced the transmit fifo without
the port lock, racing uart_flush_buffer().

The teardown tests were repeated on v7.4-rc3 with the same debug
options, on one chip: 100 unbind and bind cycles with sixteen processes
opening and closing the ports, 100 with a blocked reader, TIOCMIWAIT
waiters and a draining close pending on every port, and 300 s of flush
under transmit on all four ports, again with no lockdep, debug-objects
or kmemleak report. The probe failure injections were repeated there
with two chips, with either chip as the failing one.

Patches 1 and 2 are marked for stable. On stable trees without the
software RTS delay code the backport of patch 1 drops the rts_work and
tx_delay_tmr lines. The IRQ change in patch 1 also covers the
single-port parts, where the handler reads the port status on every
event of the line; on the multi-port parts GlobalIRQ already hides a
port with its interrupts disabled. Patch 3 is not marked: the driver
enables the chip's auto-CTS whenever CRTSCTS is set, so serial core's
software flow control path can only be taken for a CTS edge that
arrives while set_termios() is changing the flow control mode, and
serial core recomputes the stopped state when that call returns. In
practice the symptom is limited to the lockdep report.

Not addressed here: on the multi-port parts the chip-level IRQ thread
does not return while a port receives faster than the thread reads it
out, and the close of another port or an unbind then waits in
synchronize_irq() until the traffic pauses. Where that starts depends
on how long a register access to the chip takes; on the test board,
on SPI, it is a continuous stream of about 19200 baud on one port.
That predates this series and is not changed by it.

Two further items noted during the same review were left out as
improvements rather than fixes: tx_empty() reporting the transmitter
empty one character early, and the refill size and x_char ordering in
the TX path.

The patches were written and reviewed with help from an LLM assistant
(Claude), used for code reading, review of the drafts, the stress
harness and the reproducer setup; the analysis, the changes and the
testing on hardware are mine.

---
Tapio Reijonen (3):
      serial: max310x: fix use-after-free on remove
      serial: max310x: unwind only the registered ports when probe fails
      serial: max310x: hold the port lock around the CTS change

 drivers/tty/serial/max310x.c | 62 +++++++++++++++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 18 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261028-max310x-teardown-fixes-e13949736e53

Best regards,
-- 
Tapio Reijonen <tapio.reijonen@vaisala.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] serial: max310x: fix use-after-free on remove
  2026-11-20  7:33 [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes Tapio Reijonen
@ 2026-11-20  7:33 ` Tapio Reijonen
  2026-11-20  7:45   ` sashiko-bot
  2026-11-20  7:33 ` [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails Tapio Reijonen
  2026-11-20  7:33 ` [PATCH 3/3] serial: max310x: hold the port lock around the CTS change Tapio Reijonen
  2 siblings, 1 reply; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-20  7:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan, Andy Shevchenko
  Cc: linux-serial, linux-kernel, Hugo Villeneuve, stable,
	Tapio Reijonen

max310x_remove() cancels a port's timer and work items first and
unregisters the port afterwards. Until uart_remove_one_port() has shut
the port down, an open port keeps queuing its tx_work from the
interrupt handler and from start_tx(), and the RS485 code re-arms the
delay timer and rts_work from those, so a work item or the timer can
still run after the cancels, on a port that is being torn down, and
fire after the port memory has been freed.

The unregister itself queues work too: the hangup it triggers clears
DTR and RTS through set_mctrl(), which schedules md_work, so a cancel
done before uart_remove_one_port() cannot cover it. Tested with the
port memory zeroed on free, md_work ran after the unbind on the freed
port and oopsed in max310x_md_proc().

The interrupt handler is a source of its own. The IRQ enable bits
only gate the pin, the status bits stay latched regardless, so on the
single-port parts, where the handler reads the port status on every
event of the shared line, a status bit left behind by shutdown() can
still queue tx_work after the cancels. With the IRQ managed by devres
it was released only after remove() had returned.

Similar to commit 36672c8d7d14 ("serial: amba-pl011: cancel RS485
hrtimers after freeing IRQ"), stop the sources before the cancels:
unregister the ports, so that the shutdown() this triggers stops the
TX path, then free the IRQ, then cancel the timers and work items. The
IRQ goes second because the handler loops while a port has status or
RX data pending and free_irq() waits for it: freed with the ports
still open under traffic, the unbind blocked until the traffic paused.
Keep the two per-port steps in helpers; the probe error path needs
them too, with no IRQ handling since the request is probe's last step.

Fixes: 10d8b34a4217 ("serial: max310x: Driver rework")
Cc: stable@vger.kernel.org
Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>
---
 drivers/tty/serial/max310x.c | 47 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 11 deletions(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index a0ed70185555eed745d905b36c8b8f162468dd6f..f5b32303353208d9f85ae0b04d38a9abdd398d24 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1856,6 +1856,28 @@ static const struct serial_rs485 max310x_rs485_supported = {
 	.delay_rts_after_send = 1,
 };
 
+/*
+ * Unregister the port before cancelling its work: until the port is
+ * gone, an open port can queue the work and arm the timer again, and
+ * the hangup queues md_work itself. The caller frees the IRQ in
+ * between where there is one. A port that was never registered has
+ * nothing queued.
+ */
+static void max310x_port_unregister(struct max310x_one *one)
+{
+	if (test_and_clear_bit(one->port.line, max310x_lines))
+		uart_remove_one_port(&max310x_uart, &one->port);
+}
+
+static void max310x_port_cancel_work(struct max310x_one *one)
+{
+	hrtimer_cancel(&one->tx_delay_tmr);
+	cancel_work_sync(&one->rts_work);
+	cancel_work_sync(&one->tx_work);
+	cancel_work_sync(&one->md_work);
+	cancel_work_sync(&one->rs_work);
+}
+
 static int max310x_probe(struct device *dev, const struct max310x_devtype *devtype,
 			 const struct max310x_if_cfg *if_cfg,
 			 struct regmap *regmaps[], int irq)
@@ -2068,9 +2090,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 		max310x_power(&s->p[i].port, 0);
 	}
 
-	/* Setup interrupt */
-	ret = devm_request_threaded_irq(dev, irq, NULL, max310x_ist,
-					IRQF_ONESHOT | IRQF_SHARED, dev_name(dev), s);
+	/* Setup interrupt, freed by max310x_remove() */
+	ret = request_threaded_irq(irq, NULL, max310x_ist,
+				   IRQF_ONESHOT | IRQF_SHARED, dev_name(dev), s);
 	if (!ret)
 		return 0;
 
@@ -2093,16 +2115,19 @@ static void max310x_remove(struct device *dev)
 	struct max310x_port *s = dev_get_drvdata(dev);
 	int i;
 
-	for (i = 0; i < s->devtype->nr; i++) {
-		hrtimer_cancel(&s->p[i].tx_delay_tmr);
-		cancel_work_sync(&s->p[i].rts_work);
-		cancel_work_sync(&s->p[i].tx_work);
-		cancel_work_sync(&s->p[i].md_work);
-		cancel_work_sync(&s->p[i].rs_work);
+	/*
+	 * The handler loops while a port has status or RX data pending and
+	 * free_irq() waits for it: unregister first, so that the shutdown()
+	 * this triggers masks the interrupts and stops the transmitter.
+	 */
+	for (i = 0; i < s->devtype->nr; i++)
+		max310x_port_unregister(&s->p[i]);
 
-		if (test_and_clear_bit(s->p[i].port.line, max310x_lines))
-			uart_remove_one_port(&max310x_uart, &s->p[i].port);
+	/* The handler queues tx_work from latched status regardless of IRQEN */
+	free_irq(s->p[0].port.irq, s);
 
+	for (i = 0; i < s->devtype->nr; i++) {
+		max310x_port_cancel_work(&s->p[i]);
 		max310x_power(&s->p[i].port, 0);
 	}
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails
  2026-11-20  7:33 [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes Tapio Reijonen
  2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
@ 2026-11-20  7:33 ` Tapio Reijonen
  2026-11-20  7:39   ` sashiko-bot
  2026-11-20  7:33 ` [PATCH 3/3] serial: max310x: hold the port lock around the CTS change Tapio Reijonen
  2 siblings, 1 reply; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-20  7:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan, Andy Shevchenko
  Cc: linux-serial, linux-kernel, Hugo Villeneuve, stable,
	Tapio Reijonen

uart_add_one_port() queues work on the port it registers: set_mctrl()
schedules md_work or, with RS485 enabled at boot, the RS485
configuration it applies schedules rs_work instead. When the IRQ
request or the registration of a later port then fails, the error path
unregisters the ports but leaves that work queued, and it runs after
probe has returned and the port memory has been freed.

The same loop walks every port, and a port the register loop never
reached still has line 0 from the allocation. If another chip holds
line 0, the loop clears that chip's bit in max310x_lines.
uart_remove_one_port() returns early for a port that was never
registered, so nothing is unregistered, but line 0 is now marked free
while the other chip still uses it: the next probe is given line 0 and
fails in uart_add_one_port() with -EINVAL, and when the other chip is
removed its port 0 is skipped and stays registered on freed memory.
Reachable with two chips when the second one defers on a GPIO, for
example.

Unwind from the failure index down, with the removal helpers, so that
only the ports that were registered are unregistered and have their
work items cancelled, and take the exits that come before any
registration straight to the clock release.

Fixes: 78adccac1ff9 ("serial: max310x: Assign port line automatically")
Fixes: 5d888f1c32e2 ("serial: max310x: simplify probe() and remove() error handling")
Cc: stable@vger.kernel.org
Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>
---
 drivers/tty/serial/max310x.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index f5b32303353208d9f85ae0b04d38a9abdd398d24..179f5f4cc7b2f994c1dfd1b498878f4f7d6a3299 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1960,7 +1960,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 					       MAX310X_PORT_STARTUP_TIMEOUT_US);
 		if (ret) {
 			ret = dev_err_probe(dev, -EAGAIN, "port reset failed\n");
-			goto out_uart;
+			goto out_clk;
 		}
 
 		regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1);
@@ -1968,7 +1968,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 
 	ret = max310x_set_ref_clk(dev, s, freq, &uartclk, xtal);
 	if (ret < 0)
-		goto out_uart;
+		goto out_clk;
 
 	dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk);
 
@@ -2029,7 +2029,7 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 	s->gpio.can_sleep	= 1;
 	ret = devm_gpiochip_add_data(dev, &s->gpio, s);
 	if (ret)
-		goto out_uart;
+		goto out_clk;
 #endif
 
 	for (i = 0; i < devtype->nr; i++) {
@@ -2099,9 +2099,9 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty
 	dev_err(dev, "Unable to request IRQ %i\n", irq);
 
 out_uart:
-	for (i = 0; i < devtype->nr; i++) {
-		if (test_and_clear_bit(s->p[i].port.line, max310x_lines))
-			uart_remove_one_port(&max310x_uart, &s->p[i].port);
+	while (i--) {
+		max310x_port_unregister(&s->p[i]);
+		max310x_port_cancel_work(&s->p[i]);
 	}
 
 out_clk:

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] serial: max310x: hold the port lock around the CTS change
  2026-11-20  7:33 [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes Tapio Reijonen
  2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
  2026-11-20  7:33 ` [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails Tapio Reijonen
@ 2026-11-20  7:33 ` Tapio Reijonen
  2026-11-20  7:41   ` sashiko-bot
  2 siblings, 1 reply; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-20  7:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan, Andy Shevchenko
  Cc: linux-serial, linux-kernel, Hugo Villeneuve, Tapio Reijonen

uart_handle_cts_change() has to be called with the port lock held: it
updates the CTS counter and, in software flow control mode, hw_stopped
and the transmitter through start_tx() and stop_tx(), all under the
lock. The interrupt thread calls it without the lock, which lockdep
reports on the first CTS edge.

Take the lock around the call, after the register read, since the read
is a bus transfer that sleeps and must not happen under the spinlock.

Use uart_port_lock_irqsave() for it:

- irqsave, because the delay timer takes the same lock from hardirq
  context while this code runs in a thread with interrupts on;
- the serial core accessor rather than spin_lock_irqsave(), because
  that is how drivers take the port lock, and start_tx(), which
  uart_handle_cts_change() may call, drops and retakes it with
  uart_port_unlock() and uart_port_lock().

Fixes: f65444187a66 ("serial: New serial driver MAX310X")
Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>
---
 drivers/tty/serial/max310x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 179f5f4cc7b2f994c1dfd1b498878f4f7d6a3299..b2d887316957c2ca46e83efab08a537fc584b407 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1043,7 +1043,8 @@ static irqreturn_t max310x_port_irq(struct max310x_port *s, int portno)
 
 		if (ists & MAX310X_IRQ_CTS_BIT) {
 			lsr = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG);
-			uart_handle_cts_change(port, lsr & MAX310X_LSR_CTS_BIT);
+			scoped_guard(uart_port_lock_irqsave, port)
+				uart_handle_cts_change(port, lsr & MAX310X_LSR_CTS_BIT);
 		}
 		if (rxlen)
 			max310x_handle_rx(port, rxlen);

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails
  2026-11-20  7:33 ` [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails Tapio Reijonen
@ 2026-11-20  7:39   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-20  7:39 UTC (permalink / raw)
  To: Tapio Reijonen; +Cc: linux-serial

> uart_add_one_port() queues work on the port it registers: set_mctrl()
> schedules md_work or, with RS485 enabled at boot, the RS485
> configuration it applies schedules rs_work instead. When the IRQ
> request or the registration of a later port then fails, the error path
> unregisters the ports but leaves that work queued, and it runs after
> probe has returned and the port memory has been freed.
> 
> The same loop walks every port, and a port the register loop never
> reached still has line 0 from the allocation. If another chip holds
> line 0, the loop clears that chip's bit in max310x_lines.
> uart_remove_one_port() returns early for a port that was never
> registered, so nothing is unregistered, but line 0 is now marked free
> while the other chip still uses it: the next probe is given line 0 and
> fails in uart_add_one_port() with -EINVAL, and when the other chip is
> removed its port 0 is skipped and stays registered on freed memory.
> Reachable with two chips when the second one defers on a GPIO, for
> example.
> 
> Unwind from the failure index down, with the removal helpers, so that
> only the ports that were registered are unregistered and have their
> work items cancelled, and take the exits that come before any
> registration straight to the clock release.
> 
> Fixes: 78adccac1ff9 ("serial: max310x: Assign port line automatically")
> Fixes: 5d888f1c32e2 ("serial: max310x: simplify probe() and remove() error handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-max310x-teardown-fixes-v1-0-eb52c8b612df@vaisala.com?part=2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] serial: max310x: hold the port lock around the CTS change
  2026-11-20  7:33 ` [PATCH 3/3] serial: max310x: hold the port lock around the CTS change Tapio Reijonen
@ 2026-11-20  7:41   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-20  7:41 UTC (permalink / raw)
  To: Tapio Reijonen; +Cc: linux-serial

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] serial: max310x: lockless access to xmit_fifo in
  max310x_handle_tx() [1]
--

commit b6f9f6d1c6352edbe4d9493e77cb10be6d1f66a0
Author: Tapio Reijonen <tapio.reijonen@vaisala.com>

serial: max310x: hold the port lock around the CTS change

This commit acquires the UART port lock around uart_handle_cts_change() in
max310x_port_irq().

> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index 179f5f4cc7b2f..b2d887316957c 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
> @@ -1043,7 +1043,8 @@ static irqreturn_t max310x_port_irq(struct max310x_port *s, int portno)
>  
>  		if (ists & MAX310X_IRQ_CTS_BIT) {
>  			lsr = max310x_port_read(port, MAX310X_LSR_IRQSTS_REG);
> -			uart_handle_cts_change(port, lsr & MAX310X_LSR_CTS_BIT);
> +			scoped_guard(uart_port_lock_irqsave, port)
> +				uart_handle_cts_change(port, lsr & MAX310X_LSR_CTS_BIT);
>  		}
>  		if (rxlen)
>  			max310x_handle_rx(port, rxlen);

[Severity: High]
This problem wasn't introduced by this patch, but does max310x_handle_tx()
also race on tport->xmit_fifo and port->icount.tx without holding port->lock
[1]?

drivers/tty/serial/max310x.c:max310x_handle_tx() {
	...
	while (!kfifo_is_empty(&tport->xmit_fifo)) {
		...
		to_send = kfifo_out_linear_ptr(&tport->xmit_fifo, &tail, txlen);
		max310x_batch_write(port, tail, to_send);
		uart_xmit_advance(port, to_send);
	}

	if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
		uart_write_wakeup(port);
}

Callers such as uart_write() modify tport->xmit_fifo under port->lock, while
the tx_work worker drains it and calls uart_xmit_advance() and
uart_write_wakeup() locklessly, which can corrupt the transmit FIFO state
and send garbage or drop characters.

[1] https://sashiko.dev/#/bug/linux-10a0ea86-42c1-439b-aa6f-385dd9c88f23

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-max310x-teardown-fixes-v1-0-eb52c8b612df@vaisala.com?part=3

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] serial: max310x: fix use-after-free on remove
  2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
@ 2026-11-20  7:45   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-20  7:45 UTC (permalink / raw)
  To: Tapio Reijonen; +Cc: linux-serial

> max310x_remove() cancels a port's timer and work items first and
> unregisters the port afterwards. Until uart_remove_one_port() has shut
> the port down, an open port keeps queuing its tx_work from the
> interrupt handler and from start_tx(), and the RS485 code re-arms the
> delay timer and rts_work from those, so a work item or the timer can
> still run after the cancels, on a port that is being torn down, and
> fire after the port memory has been freed.
> 
> The unregister itself queues work too: the hangup it triggers clears
> DTR and RTS through set_mctrl(), which schedules md_work, so a cancel
> done before uart_remove_one_port() cannot cover it. Tested with the
> port memory zeroed on free, md_work ran after the unbind on the freed
> port and oopsed in max310x_md_proc().
> 
> The interrupt handler is a source of its own. The IRQ enable bits
> [ ... ]
> them too, with no IRQ handling since the request is probe's last step.
> 
> Fixes: 10d8b34a4217 ("serial: max310x: Driver rework")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-max310x-teardown-fixes-v1-0-eb52c8b612df@vaisala.com?part=1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-20  7:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  7:33 [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes Tapio Reijonen
2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
2026-11-20  7:45   ` sashiko-bot
2026-11-20  7:33 ` [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails Tapio Reijonen
2026-11-20  7:39   ` sashiko-bot
2026-11-20  7:33 ` [PATCH 3/3] serial: max310x: hold the port lock around the CTS change Tapio Reijonen
2026-11-20  7:41   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.