Skip to content

Commit

Permalink
specialix.c: convert nested spin_lock_irqsave to spin_lock
Browse files Browse the repository at this point in the history
If spin_lock_irqsave is called twice in a row with the same second
argument, the interrupt state at the point of the second call overwrites
the value saved by the first call.  Indeed, the second call does not
need to save the interrupt state, so it is changed to a simple
spin_lock.

The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
expression lock1,lock2;
expression flags;
@@

*spin_lock_irqsave(lock1,flags)
... when != flags
*spin_lock_irqsave(lock2,flags)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Julia Lawall authored and Linus Torvalds committed Jul 20, 2009
1 parent c46a7ae commit 2547025
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions drivers/char/specialix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,10 +1809,10 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
if (clear & TIOCM_DTR)
port->MSVR &= ~MSVR_DTR;
}
spin_lock_irqsave(&bp->lock, flags);
spin_lock(&bp->lock);
sx_out(bp, CD186x_CAR, port_No(port));
sx_out(bp, CD186x_MSVR, port->MSVR);
spin_unlock_irqrestore(&bp->lock, flags);
spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags);
func_exit();
return 0;
Expand All @@ -1833,11 +1833,11 @@ static int sx_send_break(struct tty_struct *tty, int length)
port->break_length = SPECIALIX_TPS / HZ * length;
port->COR2 |= COR2_ETC;
port->IER |= IER_TXRDY;
spin_lock_irqsave(&bp->lock, flags);
spin_lock(&bp->lock);
sx_out(bp, CD186x_CAR, port_No(port));
sx_out(bp, CD186x_COR2, port->COR2);
sx_out(bp, CD186x_IER, port->IER);
spin_unlock_irqrestore(&bp->lock, flags);
spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags);
sx_wait_CCR(bp);
spin_lock_irqsave(&bp->lock, flags);
Expand Down Expand Up @@ -2023,9 +2023,9 @@ static void sx_unthrottle(struct tty_struct *tty)
if (sx_crtscts(tty))
port->MSVR |= MSVR_DTR;
/* Else clause: see remark in "sx_throttle"... */
spin_lock_irqsave(&bp->lock, flags);
spin_lock(&bp->lock);
sx_out(bp, CD186x_CAR, port_No(port));
spin_unlock_irqrestore(&bp->lock, flags);
spin_unlock(&bp->lock);
if (I_IXOFF(tty)) {
spin_unlock_irqrestore(&port->lock, flags);
sx_wait_CCR(bp);
Expand All @@ -2035,9 +2035,9 @@ static void sx_unthrottle(struct tty_struct *tty)
sx_wait_CCR(bp);
spin_lock_irqsave(&port->lock, flags);
}
spin_lock_irqsave(&bp->lock, flags);
spin_lock(&bp->lock);
sx_out(bp, CD186x_MSVR, port->MSVR);
spin_unlock_irqrestore(&bp->lock, flags);
spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags);

func_exit();
Expand All @@ -2061,10 +2061,10 @@ static void sx_stop(struct tty_struct *tty)

spin_lock_irqsave(&port->lock, flags);
port->IER &= ~IER_TXRDY;
spin_lock_irqsave(&bp->lock, flags);
spin_lock(&bp->lock);
sx_out(bp, CD186x_CAR, port_No(port));
sx_out(bp, CD186x_IER, port->IER);
spin_unlock_irqrestore(&bp->lock, flags);
spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags);

func_exit();
Expand All @@ -2089,10 +2089,10 @@ static void sx_start(struct tty_struct *tty)
spin_lock_irqsave(&port->lock, flags);
if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
port->IER |= IER_TXRDY;
spin_lock_irqsave(&bp->lock, flags);
spin_lock(&bp->lock);
sx_out(bp, CD186x_CAR, port_No(port));
sx_out(bp, CD186x_IER, port->IER);
spin_unlock_irqrestore(&bp->lock, flags);
spin_unlock(&bp->lock);
}
spin_unlock_irqrestore(&port->lock, flags);

Expand Down

0 comments on commit 2547025

Please sign in to comment.