Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: of: Fix of_gpiochip_add() error path

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: dfbd379ba9b7431e ("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>

authored by

Geert Uytterhoeven and committed by
Linus Walleij
f7299d44 7ce40277

+7 -1
+7 -1
drivers/gpio/gpiolib-of.c
··· 718 718 719 719 of_node_get(chip->of_node); 720 720 721 - return of_gpiochip_scan_gpios(chip); 721 + status = of_gpiochip_scan_gpios(chip); 722 + if (status) { 723 + of_node_put(chip->of_node); 724 + gpiochip_remove_pin_ranges(chip); 725 + } 726 + 727 + return status; 722 728 } 723 729 724 730 void of_gpiochip_remove(struct gpio_chip *chip)