Skip to content

Commit

Permalink
drivers/gpio/timbgpio.c: add missing unlock
Browse files Browse the repository at this point in the history
In an error handling case the lock is not unlocked.  The return is
converted to a goto, to share the unlock at the end of the function.

A simplified version of the semantic patch that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
expression E1;
identifier f;
@@

f (...) { <+...
* spin_lock_irqsave (E1,...);
... when != E1
* return ...;
...+> }
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: <richard.rojfors@pelagicore.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Julia Lawall authored and Linus Torvalds committed Apr 7, 2010
1 parent c70c036 commit 2a48180
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions drivers/gpio/timbgpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static int timbgpio_irq_type(unsigned irq, unsigned trigger)
unsigned long flags;
u32 lvr, flr, bflr = 0;
u32 ver;
int ret = 0;

if (offset < 0 || offset > tgpio->gpio.ngpio)
return -EINVAL;
Expand All @@ -154,8 +155,10 @@ static int timbgpio_irq_type(unsigned irq, unsigned trigger)
}

if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
if (ver < 3)
return -EINVAL;
if (ver < 3) {
ret = -EINVAL;
goto out;
}
else {
flr |= 1 << offset;
bflr |= 1 << offset;
Expand All @@ -175,9 +178,10 @@ static int timbgpio_irq_type(unsigned irq, unsigned trigger)
iowrite32(bflr, tgpio->membase + TGPIO_BFLR);

iowrite32(1 << offset, tgpio->membase + TGPIO_ICR);
spin_unlock_irqrestore(&tgpio->lock, flags);

return 0;
out:
spin_unlock_irqrestore(&tgpio->lock, flags);
return ret;
}

static void timbgpio_irq(unsigned int irq, struct irq_desc *desc)
Expand Down

0 comments on commit 2a48180

Please sign in to comment.