[PATCH] serial: 8250: Clear CON_PRINTBUFFER on port re-registration

From: Fushuai Wang

Date: Thu Apr 16 2026 - 05:34:32 EST


From: Fushuai Wang <wangfushuai@xxxxxxxxx>

When two PnP devices map to the same physical port, the serial8250 driver
removes and re-registers the console structure for the same port.

During re-registration, the console structure still has CON_PRINTBUFFER set
from the initial registration, which causes console_init_seq() to set
console->seq to syslog_seq. This results in re-printing the entire
system log buffer, which may lead to RCU stall on slow serial consoles.

Clear CON_PRINTBUFFER when re-registering a port to prevent duplicate
log printing.

Signed-off-by: Fushuai Wang <wangfushuai@xxxxxxxxx>
---
drivers/tty/serial/8250/8250_core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index d2e2c5dfef99..3465a4d93b50 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -694,6 +694,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
{
struct uart_8250_port *uart;
int ret;
+ bool was_removed = false;

if (up->port.uartclk == 0)
return -EINVAL;
@@ -716,8 +717,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
if (uart->port.type == PORT_8250_CIR)
return -ENODEV;

- if (uart->port.dev)
+ if (uart->port.dev) {
uart_remove_one_port(&serial8250_reg, &uart->port);
+ was_removed = true;
+ }

uart->port.ctrl_id = up->port.ctrl_id;
uart->port.port_id = up->port.port_id;
@@ -819,6 +822,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
&uart->capabilities);

serial8250_apply_quirks(uart);
+
+ if (was_removed && uart_console(&uart->port))
+ uart->port.cons->flags &= ~CON_PRINTBUFFER;
+
ret = uart_add_one_port(&serial8250_reg,
&uart->port);
if (ret)
--
2.36.1