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

tty, serial: Fix race and NULL check in uart_close()

Commit 46d57a449aa1 ("serial: use tty_port pointers in the core code")
contained two bugs that causes (rare) crashes:

- the rename typoed one site

- a NULL check was missed

Reported-and-tested-by: Ingo Molnar <mingo@elte.hu>
Cc: Greg KH <gregkh@suse.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+5 -2
+5 -2
drivers/serial/serial_core.c
··· 1270 1270 1271 1271 BUG_ON(!kernel_locked()); 1272 1272 1273 + if (!state) 1274 + return; 1275 + 1273 1276 uport = state->uart_port; 1274 1277 port = &state->port; 1275 1278 ··· 1319 1316 */ 1320 1317 if (port->flags & ASYNC_INITIALIZED) { 1321 1318 unsigned long flags; 1322 - spin_lock_irqsave(&port->lock, flags); 1319 + spin_lock_irqsave(&uport->lock, flags); 1323 1320 uport->ops->stop_rx(uport); 1324 - spin_unlock_irqrestore(&port->lock, flags); 1321 + spin_unlock_irqrestore(&uport->lock, flags); 1325 1322 /* 1326 1323 * Before we drop DTR, make sure the UART transmitter 1327 1324 * has completely drained; this is especially