Skip to content

Commit

Permalink
gpiolib: irqchip: prevent driver unloading if gpio is used as irq only
Browse files Browse the repository at this point in the history
Now nothing prevents GPIO driver from being unloaded if its gpios
were requested as GPIO IRQs only (without calling gpio_request()).

Hence, add calls of try_module_get()/module_put() into
gpiochip_irq_reqres/relres() to track such scenario properly.

Cc: Johan Hovold <johan@kernel.org>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Grygorii Strashko authored and Linus Walleij committed Jul 16, 2015
1 parent 049aaf9 commit 5b76e79
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,14 @@ static int gpiochip_irq_reqres(struct irq_data *d)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(d);

if (!try_module_get(chip->owner))
return -ENODEV;

if (gpiochip_lock_as_irq(chip, d->hwirq)) {
chip_err(chip,
"unable to lock HW IRQ %lu for IRQ\n",
d->hwirq);
module_put(chip->owner);
return -EINVAL;
}
return 0;
Expand All @@ -536,6 +540,7 @@ static void gpiochip_irq_relres(struct irq_data *d)
struct gpio_chip *chip = irq_data_get_irq_chip_data(d);

gpiochip_unlock_as_irq(chip, d->hwirq);
module_put(chip->owner);
}

static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset)
Expand Down

0 comments on commit 5b76e79

Please sign in to comment.