Skip to contentSkip to conversation

gpiolib: of: Correct error handling in of_get_named_gpiod_flags

PATCH In review Hans Holmberg 3 participants 3 messages Jan 9, 2015 – Jan 15, 2015 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: of: Correct error handling in of_get_named_gpiod_flags

of_get_named_gpiod_flags fails with -EPROBE_DEFER in cases where the gpio chip is available and the GPIO translation fails.

This causes drivers to be re-probed erroneusly, and hides the real problem(i.e. the GPIO number being out of range).

---
 drivers/gpio/gpiolib-of.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-of.c +8 -2
index 604dbe6..08261f2 100644
@@ -45,8 +45,14 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
 		return false;
 
 	ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags);
-	if (ret < 0)
-		return false;
+	if (ret < 0) {
+		/* We've found the gpio chip, but the translation failed.
+		 * Return true to stop looking and return the translation
+		 * error via out_gpio
+		 */
+		gg_data->out_gpio = ERR_PTR(ret);
+		return true;
+	 }
 
 	gg_data->out_gpio = gpiochip_get_desc(gc, ret);
 	return true;
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Hans Holmberg

of_get_named_gpiod_flags fails with -EPROBE_DEFER in cases where the gpio chip is available and the GPIO translation fails.

This causes drivers to be re-probed erroneusly, and hides the real problem(i.e. the GPIO number being out of range).

---
 drivers/gpio/gpiolib-of.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib-of.c +0 -0
index 604dbe6..08261f2 100644
@@ -45,8 +45,14 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
                return false;
 
        ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags);

drivers/gpio/gpiolib-of.c static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data) · line 55

Quoted 10 lines
drivers/gpio/gpiolib-of.c +8 -2
-       if (ret < 0)
-               return false;
+       if (ret < 0) {
+               /* We've found the gpio chip, but the translation failed.
+                * Return true to stop looking and return the translation
+                * error via out_gpio
+                */
+               gg_data->out_gpio = ERR_PTR(ret);
+               return true;
+        }

Nice catch.

#2 lore raw
In reply to Hans Holmberg
Quoted 7 lines · Hans Holmberg

of_get_named_gpiod_flags fails with -EPROBE_DEFER in cases where the gpio chip is available and the GPIO translation fails.

This causes drivers to be re-probed erroneusly, and hides the real problem(i.e. the GPIO number being out of range).

Patch applied for fixes with Alex's ACK.

Yours,
Linus Walleij