linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: of: fix fallback quirks handling
@ 2019-09-03 23:18 Dmitry Torokhov
  2019-09-04 12:34 ` Andy Shevchenko
  2019-09-10 10:33 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2019-09-03 23:18 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, Andreas Kemnade, linux-gpio, linux-spi, linux-kernel

We should only try to execute fallback quirks handling when previous
call returned -ENOENT, and not when we did not get -EPROBE_DEFER.
The other errors should be treated as hard errors: we did find the GPIO
description, but for some reason we failed to handle it properly.

The fallbacks should only be executed when previous handlers returned
-ENOENT, which means the mapping/description was not found.

Also let's remove the explicit deferral handling when iterating through
GPIO suffixes: it is not needed anymore as we will not be calling
fallbacks for anything but -ENOENT.

Fixes: df451f83e1fc ("gpio: of: fix Freescale SPI CS quirk handling")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/gpio/gpiolib-of.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index b034abe59f28..b45b39c48a34 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -457,36 +457,27 @@ 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);
-		/*
-		 * -EPROBE_DEFER in our case means that we found a
-		 * valid GPIO property, but no controller has been
-		 * registered so far.
-		 *
-		 * This means we don't need to look any further for
-		 * alternate name conventions, and we should really
-		 * preserve the return code for our user to be able to
-		 * retry probing later.
-		 */
-		if (IS_ERR(desc) && PTR_ERR(desc) == -EPROBE_DEFER)
-			return desc;
 
-		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
+		if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
 			break;
 	}
 
-	/* Special handling for SPI GPIOs if used */
-	if (IS_ERR(desc))
+	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
+		/* Special handling for SPI GPIOs if used */
 		desc = of_find_spi_gpio(dev, con_id, &of_flags);
-	if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER) {
+	}
+
+	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
 		/* This quirk looks up flags and all */
 		desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
 		if (!IS_ERR(desc))
 			return desc;
 	}
 
-	/* Special handling for regulator GPIOs if used */
-	if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
+	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
+		/* Special handling for regulator GPIOs if used */
 		desc = of_find_regulator_gpio(dev, con_id, &of_flags);
+	}
 
 	if (IS_ERR(desc))
 		return desc;
-- 
2.23.0.187.g17f5b7556c-goog


-- 
Dmitry

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

* Re: [PATCH] gpiolib: of: fix fallback quirks handling
  2019-09-03 23:18 [PATCH] gpiolib: of: fix fallback quirks handling Dmitry Torokhov
@ 2019-09-04 12:34 ` Andy Shevchenko
  2019-09-10 10:33 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2019-09-04 12:34 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Andreas Kemnade, linux-gpio, linux-spi, linux-kernel

On Tue, Sep 03, 2019 at 04:18:56PM -0700, Dmitry Torokhov wrote:
> We should only try to execute fallback quirks handling when previous
> call returned -ENOENT, and not when we did not get -EPROBE_DEFER.
> The other errors should be treated as hard errors: we did find the GPIO
> description, but for some reason we failed to handle it properly.
> 
> The fallbacks should only be executed when previous handlers returned
> -ENOENT, which means the mapping/description was not found.
> 
> Also let's remove the explicit deferral handling when iterating through
> GPIO suffixes: it is not needed anymore as we will not be calling
> fallbacks for anything but -ENOENT.
> 

I would rather leave extra parenthesis and comments untouched,
nevertheless, FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Fixes: df451f83e1fc ("gpio: of: fix Freescale SPI CS quirk handling")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/gpio/gpiolib-of.c | 27 +++++++++------------------
>  1 file changed, 9 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index b034abe59f28..b45b39c48a34 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -457,36 +457,27 @@ 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);
> -		/*
> -		 * -EPROBE_DEFER in our case means that we found a
> -		 * valid GPIO property, but no controller has been
> -		 * registered so far.
> -		 *
> -		 * This means we don't need to look any further for
> -		 * alternate name conventions, and we should really
> -		 * preserve the return code for our user to be able to
> -		 * retry probing later.
> -		 */
> -		if (IS_ERR(desc) && PTR_ERR(desc) == -EPROBE_DEFER)
> -			return desc;
>  
> -		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
> +		if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
>  			break;
>  	}
>  
> -	/* Special handling for SPI GPIOs if used */
> -	if (IS_ERR(desc))
> +	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
> +		/* Special handling for SPI GPIOs if used */
>  		desc = of_find_spi_gpio(dev, con_id, &of_flags);
> -	if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER) {
> +	}
> +
> +	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
>  		/* This quirk looks up flags and all */
>  		desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
>  		if (!IS_ERR(desc))
>  			return desc;
>  	}
>  
> -	/* Special handling for regulator GPIOs if used */
> -	if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
> +	if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
> +		/* Special handling for regulator GPIOs if used */
>  		desc = of_find_regulator_gpio(dev, con_id, &of_flags);
> +	}
>  
>  	if (IS_ERR(desc))
>  		return desc;
> -- 
> 2.23.0.187.g17f5b7556c-goog
> 
> 
> -- 
> Dmitry

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] gpiolib: of: fix fallback quirks handling
  2019-09-03 23:18 [PATCH] gpiolib: of: fix fallback quirks handling Dmitry Torokhov
  2019-09-04 12:34 ` Andy Shevchenko
@ 2019-09-10 10:33 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2019-09-10 10:33 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Andy Shevchenko, Andreas Kemnade, open list:GPIO SUBSYSTEM,
	linux-spi, linux-kernel

On Wed, Sep 4, 2019 at 12:18 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:

> We should only try to execute fallback quirks handling when previous
> call returned -ENOENT, and not when we did not get -EPROBE_DEFER.
> The other errors should be treated as hard errors: we did find the GPIO
> description, but for some reason we failed to handle it properly.
>
> The fallbacks should only be executed when previous handlers returned
> -ENOENT, which means the mapping/description was not found.
>
> Also let's remove the explicit deferral handling when iterating through
> GPIO suffixes: it is not needed anymore as we will not be calling
> fallbacks for anything but -ENOENT.
>
> Fixes: df451f83e1fc ("gpio: of: fix Freescale SPI CS quirk handling")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Patch applied with Andy's review tag.

Sorry for not catching this before, the reasoning with the patch
is correct and I should have noticed. Overload I guess.

Yours,
Linus Walleij

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

end of thread, other threads:[~2019-09-10 10:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-03 23:18 [PATCH] gpiolib: of: fix fallback quirks handling Dmitry Torokhov
2019-09-04 12:34 ` Andy Shevchenko
2019-09-10 10:33 ` 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).