]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
TTY: serial, use ASYNCB_CLOSING in uart_close
authorJiri Slaby <jslaby@suse.cz>
Thu, 25 Aug 2011 13:12:04 +0000 (15:12 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 25 Aug 2011 16:00:39 +0000 (09:00 -0700)
We need to move port->mutex locking after wait_until_sent in
uart_close (for rationale see next patches). But if we did it now, we
would introduce a race between close and open. This is exactly why
port->mutex is locked at the top of uart_close.

To avoid the race, we add ASYNCB_CLOSING to uart_close. Like every
other sane TTY driver. Thanks to tty_port_block_til_ready used in
uart_open we will have this for free. Then we can move the port->mutex
lock.

Also note that this will make the conversion to tty_port helpers
easier. They are currently handling ASYNC_CLOSING flag correctly.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/tty/serial/serial_core.c

index 3844980b397f925d1d4ddb8d8e4d847390405203..849bd0d06b2cebb192b910b8c6bdbd1e2c55aae6 100644 (file)
@@ -1288,6 +1288,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
         * the line discipline to only process XON/XOFF characters by
         * setting tty->closing.
         */
+       set_bit(ASYNCB_CLOSING, &port->flags);
        tty->closing = 1;
        spin_unlock_irqrestore(&port->lock, flags);
 
@@ -1335,8 +1336,10 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
         * Wake up anyone trying to open this port.
         */
        clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
+       clear_bit(ASYNCB_CLOSING, &port->flags);
        spin_unlock_irqrestore(&port->lock, flags);
        wake_up_interruptible(&port->open_wait);
+       wake_up_interruptible(&port->close_wait);
 
 done:
        mutex_unlock(&port->mutex);