[PATCH] serial: 8250: Lock saved status flag resets during startup
From: Zhu Jun
Date: Wed Nov 11 2026 - 03:46:07 EST
serial8250_do_startup() clears lsr_saved_flags and msr_saved_flags after
installing the IRQ handler and starting the port timer. An interrupt or
console write can access these flags concurrently under the port lock,
as reported by KCSAN.
Hold the port lock while clearing the interrupt registers and resetting
the saved flags, so the reset is serialized with their other users.
Fixes: ad4c2aa6354f ("Serial 8250: handle saving the clear-on-read bits from the LSR and MSR")
Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
---
drivers/tty/serial/8250/8250_port.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 36b2b0a2c05c..dc5e002332be 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2386,9 +2386,11 @@ int serial8250_do_startup(struct uart_port *port)
* saved flags to avoid getting false values from polling
* routines or the previous session.
*/
- serial8250_clear_interrupts(port);
- up->lsr_saved_flags = 0;
- up->msr_saved_flags = 0;
+ scoped_guard(uart_port_lock_irqsave, port) {
+ serial8250_clear_interrupts(port);
+ up->lsr_saved_flags = 0;
+ up->msr_saved_flags = 0;
+ }
/*
* Request DMA channels for both RX and TX.
--
2.51.0