Commit 25470256 authored by Julia Lawall's avatar Julia Lawall Committed by Linus Torvalds
Browse files

specialix.c: convert nested spin_lock_irqsave to spin_lock

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: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c46a7aec
...@@ -1809,10 +1809,10 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file, ...@@ -1809,10 +1809,10 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
if (clear & TIOCM_DTR) if (clear & TIOCM_DTR)
port->MSVR &= ~MSVR_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_CAR, port_No(port));
sx_out(bp, CD186x_MSVR, port->MSVR); sx_out(bp, CD186x_MSVR, port->MSVR);
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
func_exit(); func_exit();
return 0; return 0;
...@@ -1833,11 +1833,11 @@ static int sx_send_break(struct tty_struct *tty, int length) ...@@ -1833,11 +1833,11 @@ static int sx_send_break(struct tty_struct *tty, int length)
port->break_length = SPECIALIX_TPS / HZ * length; port->break_length = SPECIALIX_TPS / HZ * length;
port->COR2 |= COR2_ETC; port->COR2 |= COR2_ETC;
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_CAR, port_No(port));
sx_out(bp, CD186x_COR2, port->COR2); sx_out(bp, CD186x_COR2, port->COR2);
sx_out(bp, CD186x_IER, port->IER); sx_out(bp, CD186x_IER, port->IER);
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
sx_wait_CCR(bp); sx_wait_CCR(bp);
spin_lock_irqsave(&bp->lock, flags); spin_lock_irqsave(&bp->lock, flags);
...@@ -2023,9 +2023,9 @@ static void sx_unthrottle(struct tty_struct *tty) ...@@ -2023,9 +2023,9 @@ static void sx_unthrottle(struct tty_struct *tty)
if (sx_crtscts(tty)) if (sx_crtscts(tty))
port->MSVR |= MSVR_DTR; port->MSVR |= MSVR_DTR;
/* Else clause: see remark in "sx_throttle"... */ /* 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)); sx_out(bp, CD186x_CAR, port_No(port));
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock(&bp->lock);
if (I_IXOFF(tty)) { if (I_IXOFF(tty)) {
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
sx_wait_CCR(bp); sx_wait_CCR(bp);
...@@ -2035,9 +2035,9 @@ static void sx_unthrottle(struct tty_struct *tty) ...@@ -2035,9 +2035,9 @@ static void sx_unthrottle(struct tty_struct *tty)
sx_wait_CCR(bp); sx_wait_CCR(bp);
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
} }
spin_lock_irqsave(&bp->lock, flags); spin_lock(&bp->lock);
sx_out(bp, CD186x_MSVR, port->MSVR); sx_out(bp, CD186x_MSVR, port->MSVR);
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
func_exit(); func_exit();
...@@ -2061,10 +2061,10 @@ static void sx_stop(struct tty_struct *tty) ...@@ -2061,10 +2061,10 @@ static void sx_stop(struct tty_struct *tty)
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
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_CAR, port_No(port));
sx_out(bp, CD186x_IER, port->IER); sx_out(bp, CD186x_IER, port->IER);
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock(&bp->lock);
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
func_exit(); func_exit();
...@@ -2089,10 +2089,10 @@ static void sx_start(struct tty_struct *tty) ...@@ -2089,10 +2089,10 @@ static void sx_start(struct tty_struct *tty)
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) { if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
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_CAR, port_No(port));
sx_out(bp, CD186x_IER, port->IER); sx_out(bp, CD186x_IER, port->IER);
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock(&bp->lock);
} }
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment