Message ID | 20190328131349.18838-2-geert+renesas@glider.be |
---|---|
State | New |
Headers | show |
Series | gpio: Failure path fixes | expand |
On 3/28/2019 6:43 PM, Geert Uytterhoeven wrote: > 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> -Mukesh > --- > drivers/gpio/gpiolib-of.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c > index 8b9c3ab70f6eade4..257be7bac032a855 100644 > --- a/drivers/gpio/gpiolib-of.c > +++ b/drivers/gpio/gpiolib-of.c > @@ -717,7 +717,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)
On Thu, Mar 28, 2019 at 2:13 PM Geert Uytterhoeven <geert+renesas@glider.be> wrote: > 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> Patch applied. Yours, Linus Walleij
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 8b9c3ab70f6eade4..257be7bac032a855 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -717,7 +717,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)
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> --- drivers/gpio/gpiolib-of.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)