Skip to content

Commit

Permalink
gpio: of: Fix of_gpiochip_add() error path
Browse files Browse the repository at this point in the history
If the call to of_gpiochip_scan_gpios() in of_gpiochip_add() fails, no
error handling is performed.  This lead to the need of callers to call
of_gpiochip_remove() on failure, which causes "BAD of_node_put() on ..."
if the failure happened before the call to of_node_get().

Fix this by adding proper error handling.

Note that calling gpiochip_remove_pin_ranges() multiple times causes no
harm: subsequent calls are a no-op.

Fixes: dfbd379 ("gpio: of: Return error if gpio hog configuration failed")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Geert Uytterhoeven authored and Linus Walleij committed Mar 28, 2019
1 parent 7ce4027 commit f7299d4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/gpio/gpiolib-of.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,13 @@ int of_gpiochip_add(struct gpio_chip *chip)

of_node_get(chip->of_node);

return of_gpiochip_scan_gpios(chip);
status = of_gpiochip_scan_gpios(chip);
if (status) {
of_node_put(chip->of_node);
gpiochip_remove_pin_ranges(chip);
}

return status;
}

void of_gpiochip_remove(struct gpio_chip *chip)
Expand Down

0 comments on commit f7299d4

Please sign in to comment.