Re: [linus:master] [serial] 43066e3222: BUG:kernel_NULL_pointer_dereference,address

Tony Lindgren
2024-04-04T06:54:36Z

* Andy Shevchenko <andriy.shevchenko@linux.intel.com> [240403 14:00]:
> Probably we need to check if the port is still open...
>
> P.S. AFAIU the state / xmit is invalid pointer or so.
>
> Culprit line: serial_out(up, UART_TX, xmit->buf[xmit->tail]);

Maybe we can set UPF_DEAD a bit earlier as below?

Regards,

Tony

8< ---------------------------
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3442,8 +3442,6 @@ void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port

mutex_lock(&port_mutex);

- port->flags |= UPF_DEAD;
-
serial_core_remove_one_port(drv, port);

/* Note that struct uart_port *port is no longer valid at this point */
diff --git a/drivers/tty/serial/serial_port.c b/drivers/tty/serial/serial_port.c
index 22b9eeb23e68a..1571ef721ef10 100644
--- a/drivers/tty/serial/serial_port.c
+++ b/drivers/tty/serial/serial_port.c
@@ -104,6 +104,7 @@ EXPORT_SYMBOL(uart_add_one_port);

void uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)
{
+ port->flags |= UPF_DEAD;
serial_ctrl_unregister_port(drv, port);
}
EXPORT_SYMBOL(uart_remove_one_port);