Commit 6d86750c authored by Johan Hovold's avatar Johan Hovold Committed by Linus Walleij

gpio: fix gpio leak in gpiochip_add error path

Make sure to free any hogged gpios on errors in gpiochip_add.

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

Fixes: f625d460 ("gpio: add GPIO hogging mechanism")
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 030bbdbf
...@@ -53,6 +53,11 @@ static DEFINE_MUTEX(gpio_lookup_lock); ...@@ -53,6 +53,11 @@ static DEFINE_MUTEX(gpio_lookup_lock);
static LIST_HEAD(gpio_lookup_list); static LIST_HEAD(gpio_lookup_list);
LIST_HEAD(gpio_chips); 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) static inline void desc_set_label(struct gpio_desc *d, const char *label)
{ {
d->label = label; d->label = label;
...@@ -297,6 +302,7 @@ int gpiochip_add(struct gpio_chip *chip) ...@@ -297,6 +302,7 @@ int gpiochip_add(struct gpio_chip *chip)
err_remove_chip: err_remove_chip:
acpi_gpiochip_remove(chip); acpi_gpiochip_remove(chip);
gpiochip_free_hogs(chip);
of_gpiochip_remove(chip); of_gpiochip_remove(chip);
spin_lock_irqsave(&gpio_lock, flags); spin_lock_irqsave(&gpio_lock, flags);
list_del(&chip->list); list_del(&chip->list);
...@@ -313,10 +319,6 @@ int gpiochip_add(struct gpio_chip *chip) ...@@ -313,10 +319,6 @@ int gpiochip_add(struct gpio_chip *chip)
} }
EXPORT_SYMBOL_GPL(gpiochip_add); 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 * gpiochip_remove() - unregister a gpio_chip
* @chip: the chip to unregister * @chip: the chip to unregister
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment