linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: of_find_gpio(): Don't discard errors
@ 2016-07-01 15:40 Lars-Peter Clausen
  2016-07-06  8:38 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Lars-Peter Clausen @ 2016-07-01 15:40 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot; +Cc: linux-gpio, Lars-Peter Clausen

Since commit dd34c37aa3e8 ("gpio: of: Allow -gpio suffix for property
names") when requesting a GPIO from the devicetree gpiolib looks for
properties with both the '-gpio' and the '-gpios' suffix. This was
implemented by first searching for the property with the '-gpios' suffix
and if that yields an error try the '-gpio' suffix. This approach has the
issue that any error returned when looking for the '-gpios' suffix is
silently discarded.

Commit 06fc3b70f1dc ("gpio: of: Fix handling for deferred probe for -gpio
suffix") partially addressed the issue by treating the EPROBE_DEFER error
as a special condition. This fixed the case when the property is specified,
but the GPIO provider is not ready yet. But there are other cases in which
of_get_named_gpiod_flags() returns an error even though the property is
specified, e.g. if the specification is incorrect.

of_find_gpio() should only try to look for the property with the '-gpio'
suffix if no property with the '-gpios' suffix was found. If the property
was not found of_get_named_gpiod_flags() will return -ENOENT, so update the
condition to abort and propagate the error to the caller in all other
cases.

This is important for gpiod_get_optinal() and friends to behave correctly
in case the specifier contains errors. Without this patch they'll return
NULL if the property uses the '-gpios' suffix and the specifier contains
errors, which falsely indicates to the caller that no GPIO was specified.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6566b93..8f1d51b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2838,7 +2838,7 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 
 		desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
 						&of_flags);
-		if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER))
+		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
 			break;
 	}
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpiolib: of_find_gpio(): Don't discard errors
  2016-07-01 15:40 [PATCH] gpiolib: of_find_gpio(): Don't discard errors Lars-Peter Clausen
@ 2016-07-06  8:38 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2016-07-06  8:38 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Alexandre Courbot, linux-gpio@vger.kernel.org

On Fri, Jul 1, 2016 at 5:40 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:

> Since commit dd34c37aa3e8 ("gpio: of: Allow -gpio suffix for property
> names") when requesting a GPIO from the devicetree gpiolib looks for
> properties with both the '-gpio' and the '-gpios' suffix. This was
> implemented by first searching for the property with the '-gpios' suffix
> and if that yields an error try the '-gpio' suffix. This approach has the
> issue that any error returned when looking for the '-gpios' suffix is
> silently discarded.
>
> Commit 06fc3b70f1dc ("gpio: of: Fix handling for deferred probe for -gpio
> suffix") partially addressed the issue by treating the EPROBE_DEFER error
> as a special condition. This fixed the case when the property is specified,
> but the GPIO provider is not ready yet. But there are other cases in which
> of_get_named_gpiod_flags() returns an error even though the property is
> specified, e.g. if the specification is incorrect.
>
> of_find_gpio() should only try to look for the property with the '-gpio'
> suffix if no property with the '-gpios' suffix was found. If the property
> was not found of_get_named_gpiod_flags() will return -ENOENT, so update the
> condition to abort and propagate the error to the caller in all other
> cases.
>
> This is important for gpiod_get_optinal() and friends to behave correctly
> in case the specifier contains errors. Without this patch they'll return
> NULL if the property uses the '-gpios' suffix and the specifier contains
> errors, which falsely indicates to the caller that no GPIO was specified.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

This makes all kind of sense. Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-06  8:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-01 15:40 [PATCH] gpiolib: of_find_gpio(): Don't discard errors Lars-Peter Clausen
2016-07-06  8:38 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).