Skip to contentSkip to conversation

gpiolib: Keep returning EPROBE_DEFER when we should

PATCH In review Maxime Ripard 3 participants 7 messages Feb 21, 2018 – Feb 26, 2018 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: Keep returning EPROBE_DEFER when we should

Commits c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties") and 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties") have introduced a regression in the way error codes from of_get_named_gpiod_flags are handled.

Previously, those errors codes were returned immediately, but the two commits mentioned above are now overwriting the error pointer, meaning that whatever value has been returned will be dropped in favor of whatever the two new functions will return.

This might not be a big deal except for EPROBE_DEFER, on which GPIOlib customers will depend on, and that will now be returned as an hard error which means that they will not probe anymore, instead of gently deferring their probe.

Since EPROBE_DEFER basically means that we have found a valid property but there was no GPIO controller registered to handle it, fix this issues by returning it as soon as we encounter it.

Fixes c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties")
Fixes 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties")
---
 drivers/gpio/gpiolib-of.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpio/gpiolib-of.c +13 -0
index 564bb7a31da4..c92847ff5d0a 100644
@@ -243,6 +243,19 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 						&of_flags);
 		if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
 			break;
+
+		/*
+		 * -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;
 	}
 
 	/* Special handling for SPI GPIOs if used */
Signature · 1 line
2.14.3
#1 lore raw
Quoted 15 lines · Maxime Ripard

Commits c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties") and 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties") have introduced a regression in the way error codes from of_get_named_gpiod_flags are handled.

Previously, those errors codes were returned immediately, but the two commits mentioned above are now overwriting the error pointer, meaning that whatever value has been returned will be dropped in favor of whatever the two new functions will return.

This might not be a big deal except for EPROBE_DEFER, on which GPIOlib customers will depend on, and that will now be returned as an hard error which means that they will not probe anymore, instead of gently deferring their probe.

Quoted 7 lines

Since EPROBE_DEFER basically means that we have found a valid property but there was no GPIO controller registered to handle it, fix this issues by returning it as soon as we encounter it.

Fixes c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties")
Fixes 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties")

Whoops sorry for that, patch applied for fixes.

Thanks you for your help!

Yours,
Linus Walleij

#2 lore raw

Hi Linus

Quoted 22 lines · Linus Walleij
Quoted 19 lines · Maxime Ripard

Commits c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties") and 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties") have introduced a regression in the way error codes from of_get_named_gpiod_flags are handled.

Previously, those errors codes were returned immediately, but the two commits mentioned above are now overwriting the error pointer, meaning that whatever value has been returned will be dropped in favor of whatever the two new functions will return.

This might not be a big deal except for EPROBE_DEFER, on which GPIOlib customers will depend on, and that will now be returned as an hard error which means that they will not probe anymore, instead of gently deferring their probe.

Since EPROBE_DEFER basically means that we have found a valid property but there was no GPIO controller registered to handle it, fix this issues by returning it as soon as we encounter it.

Quoted 5 lines
Quoted 3 lines
Fixes c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties")
Fixes 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties")

Whoops sorry for that, patch applied for fixes.

Would this patch be any better?

https://www.spinics.net/lists/linux-gpio/msg28160.html

Not sure if of_find_spi_gpio() and of_find_regulator_gpio() return EPROBE_DEFER as well.

ChenYu

#3 lore raw
Quoted 27 lines · Chen-Yu Tsai
Quoted 26 lines · Linus Walleij
Quoted 22 lines · Maxime Ripard

Commits c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties") and 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties") have introduced a regression in the way error codes from of_get_named_gpiod_flags are handled.

Previously, those errors codes were returned immediately, but the two commits mentioned above are now overwriting the error pointer, meaning that whatever value has been returned will be dropped in favor of whatever the two new functions will return.

This might not be a big deal except for EPROBE_DEFER, on which GPIOlib customers will depend on, and that will now be returned as an hard error which means that they will not probe anymore, instead of gently deferring their probe.

Since EPROBE_DEFER basically means that we have found a valid property but there was no GPIO controller registered to handle it, fix this issues by returning it as soon as we encounter it.

Fixes c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties")
Fixes 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties")
Quoted 8 lines
Quoted 1 line

Whoops sorry for that, patch applied for fixes.

Would this patch be any better?

https://www.spinics.net/lists/linux-gpio/msg28160.html

Not sure if of_find_spi_gpio() and of_find_regulator_gpio() return EPROBE_DEFER as well.

Ah sorry I missed the patch, too much patches in my Inbox again, I wish I was better at this :/

I think Maxime's patch is nice since it clearly bails out of the loop as soon as we get deferral.

But we want the second part of your patch as well. If of_find_spi_gpio() returns -EPROBE_DEFER it should return.

I will look into it.

Yours,
Linus Walleij

#4 lore raw
In reply to Linus Walleij
Quoted 22 lines · Linus Walleij
Quoted 19 lines · Maxime Ripard

Commits c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties") and 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties") have introduced a regression in the way error codes from of_get_named_gpiod_flags are handled.

Previously, those errors codes were returned immediately, but the two commits mentioned above are now overwriting the error pointer, meaning that whatever value has been returned will be dropped in favor of whatever the two new functions will return.

This might not be a big deal except for EPROBE_DEFER, on which GPIOlib customers will depend on, and that will now be returned as an hard error which means that they will not probe anymore, instead of gently deferring their probe.

Since EPROBE_DEFER basically means that we have found a valid property but there was no GPIO controller registered to handle it, fix this issues by returning it as soon as we encounter it.

Quoted 7 lines
Quoted 3 lines
Fixes c85823390215 ("gpio: of: Support SPI nonstandard GPIO properties")
Fixes 6a537d48461d ("gpio: of: Support regulator nonstandard GPIO properties")

Whoops sorry for that, patch applied for fixes.

Thanks you for your help!

This is slightly embarrassing, but that patch doesn't actually fix anything. I tried to be smart and rework it to look nicer, and obviously failed.

Can you squash
http://code.bulix.org/z1vkt1-286673

in the commit?

Maxime

Signature · 3 lines
Maxime Ripard, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw
Quoted 4 lines · Maxime Ripard
Quoted 3 lines · Linus Walleij

On Wed, Feb 21, 2018 at 9:11 AM, Maxime Ripard
<[email protected]> wrote:

Quoted 8 lines

This is slightly embarrassing, but that patch doesn't actually fix anything. I tried to be smart and rework it to look nicer, and obviously failed.

Can you squash
http://code.bulix.org/z1vkt1-286673

in the commit?

This site is down. Can you send a new version of the patch or just reply with the change inline here?

Yours,
Linus Walleij

#6 lore raw
Quoted 10 lines · Linus Walleij
Quoted 8 lines · Maxime Ripard
Quoted 3 lines · Linus Walleij

On Wed, Feb 21, 2018 at 9:11 AM, Maxime Ripard
<[email protected]> wrote:

This is slightly embarrassing, but that patch doesn't actually fix anything. I tried to be smart and rework it to look nicer, and obviously failed.

Quoted 6 lines
Quoted 4 lines

Can you squash
http://code.bulix.org/z1vkt1-286673

in the commit?

This site is down.

Sorry :/

Quoted 2 lines

Can you send a new version of the patch or just reply with the change inline here?

Here it is:

---------8<----------------

drivers/gpio/gpiolib-of.c +3 -2
index c92847ff5d0a..ae70f679459c 100644
@@ -241,8 +241,6 @@ 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) != -ENOENT))
-                       break;
 
                /*
                 * -EPROBE_DEFER in our case means that we found a
@@ -256,6 +254,9 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
                 */
                if (IS_ERR(desc) && PTR_ERR(desc) == -EPROBE_DEFER)
                        return desc;
+
+               if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
+                       break;
        }
 
        /* Special handling for SPI GPIOs if used */

----------8<-----------------

Signature · 3 lines
Maxime Ripard, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com