Skip to content

Commit

Permalink
tty, serial: Fix race and NULL check in uart_close()
Browse files Browse the repository at this point in the history
Commit 46d57a4 ("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>
  • Loading branch information
Linus Torvalds committed Oct 12, 2009
1 parent d93a8f8 commit eea7e17
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/serial/serial_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)

BUG_ON(!kernel_locked());

if (!state)
return;

uport = state->uart_port;
port = &state->port;

Expand Down Expand Up @@ -1316,9 +1319,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
*/
if (port->flags & ASYNC_INITIALIZED) {
unsigned long flags;
spin_lock_irqsave(&port->lock, flags);
spin_lock_irqsave(&uport->lock, flags);
uport->ops->stop_rx(uport);
spin_unlock_irqrestore(&port->lock, flags);
spin_unlock_irqrestore(&uport->lock, flags);
/*
* Before we drop DTR, make sure the UART transmitter
* has completely drained; this is especially
Expand Down

0 comments on commit eea7e17

Please sign in to comment.