Skip to content

Commit

Permalink
gpio: fix gpio leak in gpiochip_add error path
Browse files Browse the repository at this point in the history
Make sure to free any hogged gpios on errors in gpiochip_add.

Also move all forward declarations to the top of the file.

Fixes: f625d46 ("gpio: add GPIO hogging mechanism")
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Johan Hovold authored and Linus Walleij committed May 12, 2015
1 parent 030bbdb commit 6d86750
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ static DEFINE_MUTEX(gpio_lookup_lock);
static LIST_HEAD(gpio_lookup_list);
LIST_HEAD(gpio_chips);


static void gpiochip_free_hogs(struct gpio_chip *chip);
static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);


static inline void desc_set_label(struct gpio_desc *d, const char *label)
{
d->label = label;
Expand Down Expand Up @@ -297,6 +302,7 @@ int gpiochip_add(struct gpio_chip *chip)

err_remove_chip:
acpi_gpiochip_remove(chip);
gpiochip_free_hogs(chip);
of_gpiochip_remove(chip);
spin_lock_irqsave(&gpio_lock, flags);
list_del(&chip->list);
Expand All @@ -313,10 +319,6 @@ int gpiochip_add(struct gpio_chip *chip)
}
EXPORT_SYMBOL_GPL(gpiochip_add);

/* Forward-declaration */
static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
static void gpiochip_free_hogs(struct gpio_chip *chip);

/**
* gpiochip_remove() - unregister a gpio_chip
* @chip: the chip to unregister
Expand Down

0 comments on commit 6d86750

Please sign in to comment.