Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: serial_core: add tty NULL check to uart_tx_stopped

Commit 761ed4a94582 ("tty: serial_core: convert uart_close to use
tty_port_close") created a case where a port used for a console does not
get shutdown on tty closing. Then a call to uart_tx_stopped() segfaults
because the tty is NULL. This could be fixed to restore old behavior,
but we also want to allow tty_ports to work without a tty attached. So
this change to allow a NULL tty_struct is needed either way.

Fixes: 761ed4a94582 ("tty: serial_core: convert uart_close to use tty_port_close")
Reported-by: kernel test robot <xiaolong.ye@intel.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rob Herring and committed by
Greg Kroah-Hartman
a727b025 e5e89602

+1 -1
+1 -1
include/linux/serial_core.h
··· 412 412 static inline int uart_tx_stopped(struct uart_port *port) 413 413 { 414 414 struct tty_struct *tty = port->state->port.tty; 415 - if (tty->stopped || port->hw_stopped) 415 + if ((tty && tty->stopped) || port->hw_stopped) 416 416 return 1; 417 417 return 0; 418 418 }