aboutsummaryrefslogtreecommitdiffstats
path: root/net/irda/ircomm/ircomm_tty.c
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2014-06-16 09:17:06 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-10 19:06:49 -0400
commite359a4e38d229d53e28905863a1fabf41debd591 (patch)
treec70f7762dac31dad62188b7b8bb2140bea8b311a /net/irda/ircomm/ircomm_tty.c
parent5fda7a0e715c32c6dd9a39ebce8429eeafb64b7d (diff)
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 <starvik@axis.com> CC: Samuel Ortiz <samuel@sortiz.org> CC: "David S. Miller" <davem@davemloft.net> Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Acked-by: Jesper Nilsson <jesper.nilsson@axis.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/irda/ircomm/ircomm_tty.c')
-rw-r--r--net/irda/ircomm/ircomm_tty.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 2ba8b9705bb7..61ceb4cdb4a2 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -320,8 +320,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
320 __FILE__, __LINE__, tty->driver->name, port->count); 320 __FILE__, __LINE__, tty->driver->name, port->count);
321 321
322 spin_lock_irqsave(&port->lock, flags); 322 spin_lock_irqsave(&port->lock, flags);
323 if (!tty_hung_up_p(filp)) 323 port->count--;
324 port->count--;
325 port->blocked_open++; 324 port->blocked_open++;
326 spin_unlock_irqrestore(&port->lock, flags); 325 spin_unlock_irqrestore(&port->lock, flags);
327 326
@@ -458,8 +457,7 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
458 /* 457 /*
459 * If the port is the middle of closing, bail out now 458 * If the port is the middle of closing, bail out now
460 */ 459 */
461 if (tty_hung_up_p(filp) || 460 if (test_bit(ASYNCB_CLOSING, &self->port.flags)) {
462 test_bit(ASYNCB_CLOSING, &self->port.flags)) {
463 461
464 /* Hm, why are we blocking on ASYNC_CLOSING if we 462 /* Hm, why are we blocking on ASYNC_CLOSING if we
465 * do return -EAGAIN/-ERESTARTSYS below anyway? 463 * do return -EAGAIN/-ERESTARTSYS below anyway?