Commit 254702568da63ce6f5ad68e77d83b427da693654

Authored by Julia Lawall
Committed by Linus Torvalds
1 parent c46a7aec55

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: Julia Lawall <julia@diku.dk>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 12 additions and 12 deletions Side-by-side Diff

drivers/char/specialix.c
... ... @@ -1809,10 +1809,10 @@
1809 1809 if (clear & TIOCM_DTR)
1810 1810 port->MSVR &= ~MSVR_DTR;
1811 1811 }
1812   - spin_lock_irqsave(&bp->lock, flags);
  1812 + spin_lock(&bp->lock);
1813 1813 sx_out(bp, CD186x_CAR, port_No(port));
1814 1814 sx_out(bp, CD186x_MSVR, port->MSVR);
1815   - spin_unlock_irqrestore(&bp->lock, flags);
  1815 + spin_unlock(&bp->lock);
1816 1816 spin_unlock_irqrestore(&port->lock, flags);
1817 1817 func_exit();
1818 1818 return 0;
1819 1819  
... ... @@ -1833,11 +1833,11 @@
1833 1833 port->break_length = SPECIALIX_TPS / HZ * length;
1834 1834 port->COR2 |= COR2_ETC;
1835 1835 port->IER |= IER_TXRDY;
1836   - spin_lock_irqsave(&bp->lock, flags);
  1836 + spin_lock(&bp->lock);
1837 1837 sx_out(bp, CD186x_CAR, port_No(port));
1838 1838 sx_out(bp, CD186x_COR2, port->COR2);
1839 1839 sx_out(bp, CD186x_IER, port->IER);
1840   - spin_unlock_irqrestore(&bp->lock, flags);
  1840 + spin_unlock(&bp->lock);
1841 1841 spin_unlock_irqrestore(&port->lock, flags);
1842 1842 sx_wait_CCR(bp);
1843 1843 spin_lock_irqsave(&bp->lock, flags);
1844 1844  
... ... @@ -2023,9 +2023,9 @@
2023 2023 if (sx_crtscts(tty))
2024 2024 port->MSVR |= MSVR_DTR;
2025 2025 /* Else clause: see remark in "sx_throttle"... */
2026   - spin_lock_irqsave(&bp->lock, flags);
  2026 + spin_lock(&bp->lock);
2027 2027 sx_out(bp, CD186x_CAR, port_No(port));
2028   - spin_unlock_irqrestore(&bp->lock, flags);
  2028 + spin_unlock(&bp->lock);
2029 2029 if (I_IXOFF(tty)) {
2030 2030 spin_unlock_irqrestore(&port->lock, flags);
2031 2031 sx_wait_CCR(bp);
2032 2032  
... ... @@ -2035,9 +2035,9 @@
2035 2035 sx_wait_CCR(bp);
2036 2036 spin_lock_irqsave(&port->lock, flags);
2037 2037 }
2038   - spin_lock_irqsave(&bp->lock, flags);
  2038 + spin_lock(&bp->lock);
2039 2039 sx_out(bp, CD186x_MSVR, port->MSVR);
2040   - spin_unlock_irqrestore(&bp->lock, flags);
  2040 + spin_unlock(&bp->lock);
2041 2041 spin_unlock_irqrestore(&port->lock, flags);
2042 2042  
2043 2043 func_exit();
2044 2044  
... ... @@ -2061,10 +2061,10 @@
2061 2061  
2062 2062 spin_lock_irqsave(&port->lock, flags);
2063 2063 port->IER &= ~IER_TXRDY;
2064   - spin_lock_irqsave(&bp->lock, flags);
  2064 + spin_lock(&bp->lock);
2065 2065 sx_out(bp, CD186x_CAR, port_No(port));
2066 2066 sx_out(bp, CD186x_IER, port->IER);
2067   - spin_unlock_irqrestore(&bp->lock, flags);
  2067 + spin_unlock(&bp->lock);
2068 2068 spin_unlock_irqrestore(&port->lock, flags);
2069 2069  
2070 2070 func_exit();
2071 2071  
... ... @@ -2089,10 +2089,10 @@
2089 2089 spin_lock_irqsave(&port->lock, flags);
2090 2090 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
2091 2091 port->IER |= IER_TXRDY;
2092   - spin_lock_irqsave(&bp->lock, flags);
  2092 + spin_lock(&bp->lock);
2093 2093 sx_out(bp, CD186x_CAR, port_No(port));
2094 2094 sx_out(bp, CD186x_IER, port->IER);
2095   - spin_unlock_irqrestore(&bp->lock, flags);
  2095 + spin_unlock(&bp->lock);
2096 2096 }
2097 2097 spin_unlock_irqrestore(&port->lock, flags);
2098 2098