Skip to content

Commit

Permalink
gpio: omap: fix error handling in omap_gpio_irq_type
Browse files Browse the repository at this point in the history
The GPIO bank will be kept powered in case if input parameters
are invalid or error occurred in omap_gpio_irq_type.

Hence, fix it by ensuring that GPIO bank will be unpowered
in case of errors and add additional check of value returned
from omap_set_gpio_triggering().

Signed-off-by: Grygorii Strashko <grygorii.strashko@linaro.org>
Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Grygorii Strashko authored and Linus Walleij committed Jun 1, 2015
1 parent 5f982c7 commit 1562e46
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/gpio/gpio-omap.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,22 +488,25 @@ static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
unsigned long flags;
unsigned offset = d->hwirq;

if (!BANK_USED(bank))
pm_runtime_get_sync(bank->dev);

if (type & ~IRQ_TYPE_SENSE_MASK)
return -EINVAL;

if (!bank->regs->leveldetect0 &&
(type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
return -EINVAL;

if (!BANK_USED(bank))
pm_runtime_get_sync(bank->dev);

spin_lock_irqsave(&bank->lock, flags);
retval = omap_set_gpio_triggering(bank, offset, type);
if (retval)
goto error;
omap_gpio_init_irq(bank, offset);
if (!omap_gpio_is_input(bank, offset)) {
spin_unlock_irqrestore(&bank->lock, flags);
return -EINVAL;
retval = -EINVAL;
goto error;
}
spin_unlock_irqrestore(&bank->lock, flags);

Expand All @@ -512,6 +515,11 @@ static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
__irq_set_handler_locked(d->irq, handle_edge_irq);

return 0;

error:
if (!BANK_USED(bank))
pm_runtime_put(bank->dev);
return retval;
}

Expand Down

0 comments on commit 1562e46

Please sign in to comment.