From e359a4e38d229d53e28905863a1fabf41debd591 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Mon, 16 Jun 2014 09:17:06 -0400 Subject: tty: Remove tty_hung_up_p() tests from tty drivers' open() Since at least before 2.6.30, it has not been possible to observe a hung up file pointer in a tty driver's open() method unless/until the driver open() releases the tty_lock() (eg., before blocking). This is because tty_open() adds the file pointer while holding the tty_lock() _and_ doesn't release the lock until after calling the tty driver's open() method. [ Before tty_lock(), this was lock_kernel(). ] Since __tty_hangup() first waits on the tty_lock() before enumerating and hanging up the open file pointers, either __tty_hangup() will wait for the tty_lock() or tty_open() will not yet have added the file pointer. For example, CPU 0 | CPU 1 | tty_open | __tty_hangup .. | .. tty_lock | .. tty_reopen | tty_lock / blocks .. | tty_add_file(tty, filp) | .. | tty->ops->open(tty, filp) | tty_port_open | tty_port_block_til_ready | .. | while (1) | .. | tty_unlock | / unblocks schedule | for each filp on tty->tty_files | f_ops = tty_hung_up_fops; | .. | tty_unlock tty_lock | .. | tty_unlock | Note that since tty_port_block_til_ready() and similar drop the tty_lock while blocking, when woken, the file pointer must then be tested for having been hung up. Also, fix bit-rotted drivers that used extra_count to track the port->count bump. CC: Mikael Starvik CC: Samuel Ortiz CC: "David S. Miller" Signed-off-by: Peter Hurley Acked-by: Jesper Nilsson Signed-off-by: Greg Kroah-Hartman --- drivers/tty/synclink.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/tty/synclink.c') diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c index d48e040..b799170 100644 --- a/drivers/tty/synclink.c +++ b/drivers/tty/synclink.c @@ -3267,7 +3267,6 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, DECLARE_WAITQUEUE(wait, current); int retval; bool do_clocal = false; - bool extra_count = false; unsigned long flags; int dcd; struct tty_port *port = &info->port; @@ -3300,10 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, __FILE__,__LINE__, tty->driver->name, port->count ); spin_lock_irqsave(&info->irq_spinlock, flags); - if (!tty_hung_up_p(filp)) { - extra_count = true; - port->count--; - } + port->count--; spin_unlock_irqrestore(&info->irq_spinlock, flags); port->blocked_open++; @@ -3342,7 +3338,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, remove_wait_queue(&port->open_wait, &wait); /* FIXME: Racy on hangup during close wait */ - if (extra_count) + if (!tty_hung_up_p(filp)) port->count++; port->blocked_open--; @@ -3403,7 +3399,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp) __FILE__,__LINE__,tty->driver->name, info->port.count); /* If port is closing, signal caller to try again */ - if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){ + if (info->port.flags & ASYNC_CLOSING){ wait_event_interruptible_tty(tty, info->port.close_wait, !(info->port.flags & ASYNC_CLOSING)); retval = ((info->port.flags & ASYNC_HUP_NOTIFY) ? -- cgit v1.1