net/irda: Hold port lock while bumping blocked_open
authorPeter Hurley <peter@hurleysoftware.com>
Tue, 5 Mar 2013 06:09:05 +0000 (06:09 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 6 Mar 2013 07:47:04 +0000 (02:47 -0500)
Although tty_lock() already protects concurrent update to
blocked_open, that fails to meet the separation-of-concerns between
tty_port and tty.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/irda/ircomm/ircomm_tty.c

index 1721dc7e43158a05c70d193ce0dbfb9b6e129593..d282bbea710e0b04d72c7b1d4b6d07d7fa041657 100644 (file)
@@ -317,8 +317,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
        spin_lock_irqsave(&port->lock, flags);
        if (!tty_hung_up_p(filp))
                port->count--;
-       spin_unlock_irqrestore(&port->lock, flags);
        port->blocked_open++;
+       spin_unlock_irqrestore(&port->lock, flags);
 
        while (1) {
                if (tty->termios.c_cflag & CBAUD)
@@ -362,8 +362,8 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
        spin_lock_irqsave(&port->lock, flags);
        if (!tty_hung_up_p(filp))
                port->count++;
-       spin_unlock_irqrestore(&port->lock, flags);
        port->blocked_open--;
+       spin_unlock_irqrestore(&port->lock, flags);
 
        IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
              __FILE__, __LINE__, tty->driver->name, port->count);