mdio_bus: Remove unneeded gpiod NULL check
Subsystems (3)
PATCH 1/1 mdio_bus: Remove unneeded gpiod NULL check
From: Fabio Estevam <[email protected]>
The gpiod API checks for NULL descriptors, so there is no need to duplicate the check in the driver.
--- drivers/net/phy/mdio_bus.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/phy/mdio_bus.c +2 -4
@@ -399,8 +399,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) }/* Put PHYs in RESET to save power */ -if (bus->reset_gpiod) -gpiod_set_value_cansleep (bus->reset_gpiod,1 ); +gpiod_set_value_cansleep (bus->reset_gpiod,1 );device_del (&bus->dev);return err;
@@ -425,8 +424,7 @@ void mdiobus_unregister(struct mii_bus *bus) }/* Put PHYs in RESET to save power */ -if (bus->reset_gpiod) -gpiod_set_value_cansleep (bus->reset_gpiod,1 ); +gpiod_set_value_cansleep (bus->reset_gpiod,1 );device_del (&bus->dev); }
Signature · 1 line
2.7.4
Quoted 5 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
The gpiod API checks for NULL descriptors, so there is no need to duplicate the check in the driver.
Signed-off-by Fabio Estevam <[email protected]>
VALIDATE_DESC is ugly. But:
Andrew
From: Fabio Estevam <[email protected]>
Date: Mon, 17 Jul 2017 18:09:09 -0300
Quoted 6 lines
From: Fabio Estevam <[email protected]>
The gpiod API checks for NULL descriptors, so there is no need to duplicate the check in the driver.
Signed-off-by Fabio Estevam <[email protected]>
Applied, thanks.
Hello!
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
The gpiod API checks for NULL descriptors, so there is no need to duplicate the check in the driver.
Won't this result in kernel WARNING when GPIO is disabled?
Quoted 1 line
Signed-off-by Fabio Estevam <[email protected]>
[...]
MBR, Sergei
Quoted 1 line · Sergei Shtylyov
Won't this result in kernel WARNING when GPIO is disabled?
Not sure if I understood your point, but gpiod_set_value_cansleep() is a no-op when the gpiod is NULL.
Quoted 1 line · Fabio Estevam
Quoted 1 line
Won't this result in kernel WARNING when GPIO is disabled?
GPIO support, I was going to type...
Quoted 2 lines
Not sure if I understood your point, but
gpiod_set_value_cansleep()is a no-op when the gpiod is NULL.
Look at the stub in <linux/gpio/consumer.h>, it has WARN_ON(1).
MBR, Sergei
Quoted 5 lines · Sergei Shtylyov
Quoted 1 line · Fabio Estevam
Quoted 1 line
Won't this result in kernel WARNING when GPIO is disabled?
Quoted 7 lines
GPIO support, I was going to type...
Quoted 2 lines
Not sure if I understood your point, but
gpiod_set_value_cansleep()is a no-op when the gpiod is NULL.Look at the stub in <
linux/gpio/consumer.h>, it hasWARN_ON(1).
This patch does not alter the behavior of the driver with respect to GPIO being disabled, so I still do not understand your concern.
Please be more specific.
Quoted 5 lines · Fabio Estevam
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Won't this result in kernel WARNING when GPIO is disabled?
GPIO support, I was going to type...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Not sure if I understood your point, but
gpiod_set_value_cansleep()is a no-op when the gpiod is NULL.Look at the stub in <
linux/gpio/consumer.h>, it hasWARN_ON(1).This patch does not alter the behavior of the driver with respect to GPIO being disabled,
No, it does -- devm_gpiod_get_optinal() will return NULL in that case,bus->reset_gpio will remanin NULL, and you're removing the NULL checks around the gpiod_set_value_cansleep() calls. Perhaps it's the problem in the GPIO support though...
Quoted 1 line
so I still do not understand your concern.
And now?
MBR, Sergei
Quoted 4 lines · Sergei Shtylyov
No, it does --
devm_gpiod_get_optinal()will return NULL in that case,bus->reset_gpiowill remanin NULL, and you're removing the NULL checks around thegpiod_set_value_cansleep()calls. Perhaps it's the problem in the GPIO support though...
It is perfectly fine to call gpiod_set_value_cansleep() with a NULL gpio descriptor.
Please take a look at drivers/gpio/gpiolib.c:
gpiod_set_value_cansleep() calls VALIDATE_DESC_VOID
Then if you look at the definition of VALIDATE_DESC_VOID you will see that it does a NULL check on desc and returns immediately if it is NULL.
This means we are safe here :-)
Quoted 7 lines · Fabio Estevam
Quoted 4 lines
No, it does --
devm_gpiod_get_optinal()will return NULL in that case,bus->reset_gpiowill remanin NULL, and you're removing the NULL checks around thegpiod_set_value_cansleep()calls. Perhaps it's the problem in the GPIO support though...It is perfectly fine to call
gpiod_set_value_cansleep()with a NULL gpio descriptor.
Depends on whether CONFIG_HPIOLIB is enabled or not.
Quoted 1 line
Please take a look at
drivers/gpio/gpiolib.c:
If CONF(G_GPIOLIB=n, the stub from <linux/gpio/consumer.h gets used.
and devm_gpiod_get_optional() will return NULL in that case.
Quoted 5 lines
gpiod_set_value_cansleep()callsVALIDATE_DESC_VOIDThen if you look at the definition of
VALIDATE_DESC_VOIDyou will see that it does a NULL check on desc and returns immediately if it is NULL.
Sre, I did see that.
Quoted 1 line
This means we are safe here :-)
Sigh...
MBR, Sergei
Andrew Lunn
maintainerQuoted 9 lines · Fabio Estevam
Quoted 7 lines · Sergei Shtylyov
Quoted 1 line · Fabio Estevam
Quoted 1 line
Won't this result in kernel WARNING when GPIO is disabled?
GPIO support, I was going to type...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Not sure if I understood your point, but
gpiod_set_value_cansleep()is a no-op when the gpiod is NULL.Look at the stub in <
linux/gpio/consumer.h>, it hasWARN_ON(1).This patch does not alter the behavior of the driver with respect to GPIO being disabled, so I still do not understand your concern.
http://elixir.free-electrons.com/linux/latest/source/include/linux/gpio/consumer.h#L345
static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
{
/* GPIO can never have been requested */
WARN_ON(1);
}But i would say this is a gpio problem. If GPIO enabled does not care, GPIO disabled should also not care.
Adding Linus Walleij.
Andrew
Hi Andrew,
Quoted 9 lines · Andrew Lunn
http://elixir.free-electrons.com/linux/latest/source/include/linux/gpio/consumer.h#L345
static inline voidgpiod_set_value_cansleep(struct gpio_desc *desc, int value){ /* GPIO can never have been requested */ WARN_ON(1); }But i would say this is a gpio problem. If GPIO enabled does not care, GPIO disabled should also not care.
Agreed.
Sergei, sorry for taking so long to understand your point.
Quoted 1 line
Adding Linus Walleij.
Just sent a RFC patch to linux-gpio.
Thanks
Quoted 21 lines · Andrew Lunn
Quoted 9 lines · Fabio Estevam
Quoted 7 lines · Sergei Shtylyov
Quoted 1 line · Fabio Estevam
Quoted 1 line
Won't this result in kernel WARNING when GPIO is disabled?
GPIO support, I was going to type...
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Not sure if I understood your point, but
gpiod_set_value_cansleep()is a no-op when the gpiod is NULL.Look at the stub in <
linux/gpio/consumer.h>, it hasWARN_ON(1).This patch does not alter the behavior of the driver with respect to GPIO being disabled, so I still do not understand your concern.
http://elixir.free-electrons.com/linux/latest/source/include/linux/gpio/consumer.h#L345
static inline voidgpiod_set_value_cansleep(struct gpio_desc *desc, int value)
Quoted 7 lines
{ /* GPIO can never have been requested */ WARN_ON(1); }But i would say this is a gpio problem. If GPIO enabled does not care, GPIO disabled should also not care.
If someone is using GPIO descriptors with GPIO disabled, i.e. calling gpiod_get() and friends, this is very likely to be a bug, and what the driver wants to do is:
depends on GPIOLIB
or
select GPIOLIB
in Kconfig. The whole optional thing is mainly a leftover from when it was possible to have a local implementation of the GPIOLIB API in some custom header file, noone sane should be doing that anymore, and if they do, they can very well face the warnings.
If someone is facing a lot of WARN_ON() messages to this, it is a clear indication that they need to fix their Kconfig and in that case it is proper.
Yours,
Linus Walleij
Quoted 10 lines
If someone is using GPIO descriptors with GPIO disabled, i.e. calling
gpiod_get()and friends, this is very likely to be a bug, and what the driver wants to do is:depends on GPIOLIB
or
select GPIOLIB
Quoted 7 lines
in
Kconfig. The whole optional thing is mainly a leftover from when it was possible to have a local implementation of the GPIOLIB API in some custom header file, noone sane should be doing that anymore, and if they do, they can very well face the warnings.If someone is facing a lot of
WARN_ON()messages to this, it is a clear indication that they need to fix theirKconfigand in that case it is proper.
Linus & Andrew,
I knew that it is already in David's pulling request. Configuring GPIOLIB is the right solution even if platform doesn't use it?
Did I miss any new patch?
Thanks.
Woojung
Quoted 15 lines · On Thu, Sep 7, 2017 at 11:30 PM, <[email protected]> wrote:
Quoted 15 lines
If someone is using GPIO descriptors with GPIO disabled, i.e. calling
gpiod_get()and friends, this is very likely to be a bug, and what the driver wants to do is:depends on GPIOLIB
or
select GPIOLIB
in
Kconfig. The whole optional thing is mainly a leftover from when it was possible to have a local implementation of the GPIOLIB API in some custom header file, noone sane should be doing that anymore, and if they do, they can very well face the warnings.
Quoted 6 lines
Quoted 2 lines
If someone is facing a lot of
WARN_ON()messages to this, it is a clear indication that they need to fix theirKconfigand in that case it is proper.Linus & Andrew,
I knew that it is already in David's pulling request. Configuring GPIOLIB is the right solution even if platform doesn't use it?
I guess?
"Platform doesn't use it" what does that mean?
Does it mean it does not call the
APIs of the GPIOLIB, does it mean it doesn't have a GPIO driver at probe (but may have one by having it probed from a module) or does it mean the platform can never have it?
If it calls the APIs, it is using it.
Yours,
Linus Walleij
Quoted 23 lines · Linus Walleij
Quoted 15 lines · On Thu, Sep 7, 2017 at 11:30 PM, <[email protected]> wrote:
Quoted 15 lines
If someone is using GPIO descriptors with GPIO disabled, i.e. calling
gpiod_get()and friends, this is very likely to be a bug, and what the driver wants to do is:depends on GPIOLIB
or
select GPIOLIB
in
Kconfig. The whole optional thing is mainly a leftover from when it was possible to have a local implementation of the GPIOLIB API in some custom header file, noone sane should be doing that anymore, and if they do, they can very well face the warnings.Quoted 6 lines
Quoted 2 lines
If someone is facing a lot of
WARN_ON()messages to this, it is a clear indication that they need to fix theirKconfigand in that case it is proper.Linus & Andrew,
I knew that it is already in David's pulling request. Configuring GPIOLIB is the right solution even if platform doesn't use it?
Quoted 8 lines
I guess?
"Platform doesn't use it" what does that mean?
Does it mean it does not call the
APIs of the GPIOLIB, does it mean it doesn't have a GPIO driver at probe (but may have one by having it probed from a module) or does it mean the platform can never have it?
I think it means CONFIG_GPIOLIB=n in the kernel because it's not needed, yet you run code (like drivers/net/phy/mdio_bus.c) that unconditionally calls into GPIOLIB and attempts to configure a given GPIO if available. This thread is actually what prompted me to write this email:
https://lkml.org/lkml/2017/9/2/3
So that's the takeway should we just conditionalize all the GPIOLIB calls from drivers/net/phy/mdio_bus.c under an #if IS_ENABLED(CONFIG_GPIOLIB) of some sort?
Quoted 3 lines
If it calls the APIs, it is using it.
It's more subtle than that, the GPIO resource may not be available just like you have disabled support for GPIOLIB in the kernel, in which case, the calls are still there, they default to their inline stubs, you get warnings, everyone panics and screams.
Signature · 1 line
Florian
Quoted 26 lines
Quoted 26 lines
Quoted 15 lines
Quoted 15 lines
If someone is using GPIO descriptors with GPIO disabled, i.e. calling
gpiod_get()and friends, this is very likely to be a bug, and what the driver wants to do is:depends on GPIOLIB
or
select GPIOLIB
in
Kconfig. The whole optional thing is mainly a leftover from when it was possible to have a local implementation of the GPIOLIB API in some custom header file, noone sane should be doing that anymore, and if they do, they can very well face the warnings.Quoted 6 lines
Quoted 2 lines
If someone is facing a lot of
WARN_ON()messages to this, it is a clear indication that they need to fix theirKconfigand in that case it is proper.Linus & Andrew,
I knew that it is already in David's pulling request. Configuring GPIOLIB is the right solution even if platform doesn't use it?
I guess?
"Platform doesn't use it" what does that mean?
Quoted 8 lines
Quoted 4 lines
Does it mean it does not call the
APIs of the GPIOLIB, does it mean it doesn't have a GPIO driver at probe (but may have one by having it probed from a module) or does it mean the platform can never have it?I think it means
CONFIG_GPIOLIB=nin the kernel because it's not needed, yet you run code (likedrivers/net/phy/mdio_bus.c) that unconditionally calls into GPIOLIB and attempts to configure a given GPIO if available.
Yes. I'm facing issue on PC which won't need GPIOLIB as default. Warning message goes away when GPIOLIB is enabled, and fortunately, Ubuntu default config has it.
So, it may not be seen by many users when with full/default configuration.
Quoted 3 lines
This thread is actually what prompted me to write this email:
Thanks for the link.
Quoted 31 lines · On 09/07/2017 02:51 PM, [email protected] wrote:
Quoted 31 lines
Quoted 30 lines
Quoted 15 lines
Quoted 15 lines
If someone is using GPIO descriptors with GPIO disabled, i.e. calling
gpiod_get()and friends, this is very likely to be a bug, and what the driver wants to do is:depends on GPIOLIB
or
select GPIOLIB
in
Kconfig. The whole optional thing is mainly a leftover from when it was possible to have a local implementation of the GPIOLIB API in some custom header file, noone sane should be doing that anymore, and if they do, they can very well face the warnings.Quoted 6 lines
Quoted 2 lines
If someone is facing a lot of
WARN_ON()messages to this, it is a clear indication that they need to fix theirKconfigand in that case it is proper.Linus & Andrew,
I knew that it is already in David's pulling request. Configuring GPIOLIB is the right solution even if platform doesn't use it?
I guess?
"Platform doesn't use it" what does that mean?
Does it mean it does not call the
APIs of the GPIOLIB, does it mean it doesn't have a GPIO driver at probe (but may have one by having it probed from a module) or does it mean the platform can never have it?
Quoted 7 lines
Quoted 3 lines
I think it means
CONFIG_GPIOLIB=nin the kernel because it's not needed, yet you run code (likedrivers/net/phy/mdio_bus.c) that unconditionally calls into GPIOLIB and attempts to configure a given GPIO if available.Yes. I'm facing issue on PC which won't need GPIOLIB as default. Warning message goes away when GPIOLIB is enabled, and fortunately, Ubuntu default config has it.
So, it may not be seen by many users when with full/default configuration.
Woojung, I suppose you are also getting a warning from gpiod_set_value_cansleep() done in mdiobus_unregister() right? With CONFIG_GPIOLIB=n devm_gpiod_get_optional() returns NULL, which we don't check as an error, on purpose however we still call gpiod_set_value_cansleep() on a NULL GPIO descriptor, so the following should do:
drivers/net/phy/mdio_bus.c +2 -1
@@ -424,7 +424,8 @@ void mdiobus_unregister(struct mii_bus *bus) }/* Put PHYs in RESET to save power */ -gpiod_set_value_cansleep (bus->reset_gpiod,1 ); +if (!IS_ERR_OR_NULL (bus->reset_gpiod)) +gpiod_set_value_cansleep (bus->reset_gpiod,1 );device_del (&bus->dev); }
Quoted 7 lines
Quoted 4 lines
This thread is actually what prompted me to write this email:
Thanks for the link.
Signature · 1 line
Florian
Quoted 21 lines
Quoted 7 lines
Quoted 3 lines
I think it means
CONFIG_GPIOLIB=nin the kernel because it's not needed, yet you run code (likedrivers/net/phy/mdio_bus.c) that unconditionally calls into GPIOLIB and attempts to configure a given GPIO if available.Yes. I'm facing issue on PC which won't need GPIOLIB as default. Warning message goes away when GPIOLIB is enabled, and fortunately, Ubuntu default config has it.
So, it may not be seen by many users when with full/default configuration.Woojung, I suppose you are also getting a warning from
gpiod_set_value_cansleep()done inmdiobus_unregister()right? WithCONFIG_GPIOLIB=ndevm_gpiod_get_optional()returns NULL, which we don't
check as an error, on purpose however we still callgpiod_set_value_cansleep()on a NULL GPIO descriptor, so the following should do:drivers/net/phy/mdio_bus.c +0
-0
drivers/net/phy/mdio_bus.c void mdiobus_unregister(struct mii_bus *bus) · line 431
Quoted 9 lines
drivers/net/phy/mdio_bus.c +2
-1@@ -424,7 +424,8 @@ void mdiobus_unregister(struct mii_bus *bus) }/* Put PHYs in RESET to save power */ -gpiod_set_value_cansleep (bus->reset_gpiod,1 ); +if (!IS_ERR_OR_NULL (bus->reset_gpiod)) +gpiod_set_value_cansleep (bus->reset_gpiod,1 );device_del (&bus->dev); }
Hi Florian,
Thanks for the patch. I'm avoiding warning with CONFIG_GPIOLIB=y for now. I'm curious that there is a final conclusion to resolve this issue, either with CONFIG_GPIOLIB=y or something else.
- Woojung
Quoted 4 lines · Florian Fainelli
I think it means
CONFIG_GPIOLIB=nin the kernel because it's not needed, yet you run code (likedrivers/net/phy/mdio_bus.c) that unconditionally calls into GPIOLIB and attempts to configure a given GPIO if available. This thread is actually what prompted me to write this email:
Yeah I think GPIOLIB should simply be selected in KConfig then.
Sent an inline patch to do that in the other reply.
Maybe I should simply delete the stubs if they confuse people.
It is possible to select GPIOLIB on any platform these days and get the right APIs, this used to not be the case but I fixed it a while back.
Alternatively we can depend on GPIOLIB but it's simpler to just select it I think, it's like a library this code uses and so that's it.
Yours,
Linus Walleij