All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
@ 2017-07-17 21:09 Fabio Estevam
  2017-07-17 21:21 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Fabio Estevam @ 2017-07-17 21:09 UTC (permalink / raw)
  To: davem; +Cc: andrew, f.fainelli, netdev, Fabio Estevam

From: Fabio Estevam <fabio.estevam@nxp.com>

The gpiod API checks for NULL descriptors, so there is no need to
duplicate the check in the driver.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/net/phy/mdio_bus.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 2df7b62c..b6f9fa6 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -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);
 }
-- 
2.7.4

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-17 21:09 [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check Fabio Estevam
@ 2017-07-17 21:21 ` Andrew Lunn
  2017-07-17 23:57 ` David Miller
  2017-07-18  9:56 ` Sergei Shtylyov
  2 siblings, 0 replies; 20+ messages in thread
From: Andrew Lunn @ 2017-07-17 21:21 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: davem, f.fainelli, netdev, Fabio Estevam

On Mon, Jul 17, 2017 at 06:09:09PM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> The gpiod API checks for NULL descriptors, so there is no need to
> duplicate the check in the driver.
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>

VALIDATE_DESC is ugly. But:

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-17 21:09 [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check Fabio Estevam
  2017-07-17 21:21 ` Andrew Lunn
@ 2017-07-17 23:57 ` David Miller
  2017-07-18  9:56 ` Sergei Shtylyov
  2 siblings, 0 replies; 20+ messages in thread
From: David Miller @ 2017-07-17 23:57 UTC (permalink / raw)
  To: festevam; +Cc: andrew, f.fainelli, netdev, fabio.estevam

From: Fabio Estevam <festevam@gmail.com>
Date: Mon, 17 Jul 2017 18:09:09 -0300

> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> The gpiod API checks for NULL descriptors, so there is no need to
> duplicate the check in the driver.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>

Applied, thanks.

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-17 21:09 [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check Fabio Estevam
  2017-07-17 21:21 ` Andrew Lunn
  2017-07-17 23:57 ` David Miller
@ 2017-07-18  9:56 ` Sergei Shtylyov
  2017-07-18 12:39   ` Fabio Estevam
  2 siblings, 1 reply; 20+ messages in thread
From: Sergei Shtylyov @ 2017-07-18  9:56 UTC (permalink / raw)
  To: Fabio Estevam, davem; +Cc: andrew, f.fainelli, netdev, Fabio Estevam

Hello!

On 7/18/2017 12:09 AM, Fabio Estevam wrote:

> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> 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?

> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
[...]

MBR, Sergei

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18  9:56 ` Sergei Shtylyov
@ 2017-07-18 12:39   ` Fabio Estevam
  2017-07-18 12:48     ` Sergei Shtylyov
  0 siblings, 1 reply; 20+ messages in thread
From: Fabio Estevam @ 2017-07-18 12:39 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, netdev, Fabio Estevam

On Tue, Jul 18, 2017 at 6:56 AM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:

>    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.

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 12:39   ` Fabio Estevam
@ 2017-07-18 12:48     ` Sergei Shtylyov
  2017-07-18 12:52       ` Fabio Estevam
  0 siblings, 1 reply; 20+ messages in thread
From: Sergei Shtylyov @ 2017-07-18 12:48 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, netdev, Fabio Estevam

On 07/18/2017 03:39 PM, Fabio Estevam wrote:

>>    Won't this result in kernel WARNING when GPIO is disabled?

    GPIO support, I was going to type...

> 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

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 12:48     ` Sergei Shtylyov
@ 2017-07-18 12:52       ` Fabio Estevam
  2017-07-18 13:02         ` Sergei Shtylyov
  2017-07-18 13:32         ` Andrew Lunn
  0 siblings, 2 replies; 20+ messages in thread
From: Fabio Estevam @ 2017-07-18 12:52 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, netdev, Fabio Estevam

On Tue, Jul 18, 2017 at 9:48 AM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> On 07/18/2017 03:39 PM, Fabio Estevam wrote:
>
>>>    Won't this result in kernel WARNING when GPIO is disabled?
>
>
>    GPIO support, I was going to type...
>
>> 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).

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.

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 12:52       ` Fabio Estevam
@ 2017-07-18 13:02         ` Sergei Shtylyov
  2017-07-18 13:09           ` Fabio Estevam
  2017-07-18 13:32         ` Andrew Lunn
  1 sibling, 1 reply; 20+ messages in thread
From: Sergei Shtylyov @ 2017-07-18 13:02 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, netdev, Fabio Estevam

On 07/18/2017 03:52 PM, Fabio Estevam wrote:

>>>>    Won't this result in kernel WARNING when GPIO is disabled?
>>
>>
>>    GPIO support, I was going to type...
>>
>>> 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).
>
> 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...

> so I still do not understand your concern.

    And now?

MBR, Sergei

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 13:02         ` Sergei Shtylyov
@ 2017-07-18 13:09           ` Fabio Estevam
  2017-07-18 13:13             ` Sergei Shtylyov
  0 siblings, 1 reply; 20+ messages in thread
From: Fabio Estevam @ 2017-07-18 13:09 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, netdev, Fabio Estevam

On Tue, Jul 18, 2017 at 10:02 AM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:

>    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...

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 :-)

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 13:09           ` Fabio Estevam
@ 2017-07-18 13:13             ` Sergei Shtylyov
  0 siblings, 0 replies; 20+ messages in thread
From: Sergei Shtylyov @ 2017-07-18 13:13 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, netdev, Fabio Estevam

On 07/18/2017 04:09 PM, Fabio Estevam wrote:

>>    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...
>
> It is perfectly fine to call gpiod_set_value_cansleep() with a NULL
> gpio descriptor.

    Depends on whether CONFIG_HPIOLIB is enabled or not.

> 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.

> 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.

    Sre, I did see that.

> This means we are safe here :-)

    Sigh...

MBR, Sergei

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 12:52       ` Fabio Estevam
  2017-07-18 13:02         ` Sergei Shtylyov
@ 2017-07-18 13:32         ` Andrew Lunn
  2017-07-19 22:37           ` Fabio Estevam
  2017-08-02 11:57           ` Linus Walleij
  1 sibling, 2 replies; 20+ messages in thread
From: Andrew Lunn @ 2017-07-18 13:32 UTC (permalink / raw)
  To: Fabio Estevam, Linus Walleij
  Cc: Sergei Shtylyov, David S. Miller, Florian Fainelli, netdev,
	Fabio Estevam

On Tue, Jul 18, 2017 at 09:52:51AM -0300, Fabio Estevam wrote:
> On Tue, Jul 18, 2017 at 9:48 AM, Sergei Shtylyov
> <sergei.shtylyov@cogentembedded.com> wrote:
> > On 07/18/2017 03:39 PM, Fabio Estevam wrote:
> >
> >>>    Won't this result in kernel WARNING when GPIO is disabled?
> >
> >
> >    GPIO support, I was going to type...
> >
> >> 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).
> 
> 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

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 13:32         ` Andrew Lunn
@ 2017-07-19 22:37           ` Fabio Estevam
  2017-08-02 11:57           ` Linus Walleij
  1 sibling, 0 replies; 20+ messages in thread
From: Fabio Estevam @ 2017-07-19 22:37 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Linus Walleij, Sergei Shtylyov, David S. Miller,
	Florian Fainelli, netdev, Fabio Estevam

Hi Andrew,

On Tue, Jul 18, 2017 at 10:32 AM, Andrew Lunn <andrew@lunn.ch> wrote:

> 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.

Agreed.

Sergei, sorry for taking so long to understand your point.

> Adding Linus Walleij.

Just sent a RFC patch to linux-gpio.

Thanks

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-07-18 13:32         ` Andrew Lunn
  2017-07-19 22:37           ` Fabio Estevam
@ 2017-08-02 11:57           ` Linus Walleij
  2017-09-07 21:30             ` Woojung.Huh
  1 sibling, 1 reply; 20+ messages in thread
From: Linus Walleij @ 2017-08-02 11:57 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Fabio Estevam, Sergei Shtylyov, David S. Miller,
	Florian Fainelli, netdev, Fabio Estevam

On Tue, Jul 18, 2017 at 3:32 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Tue, Jul 18, 2017 at 09:52:51AM -0300, Fabio Estevam wrote:
>> On Tue, Jul 18, 2017 at 9:48 AM, Sergei Shtylyov
>> <sergei.shtylyov@cogentembedded.com> wrote:
>> > On 07/18/2017 03:39 PM, Fabio Estevam wrote:
>> >
>> >>>    Won't this result in kernel WARNING when GPIO is disabled?
>> >
>> >
>> >    GPIO support, I was going to type...
>> >
>> >> 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).
>>
>> 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.

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

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

* RE: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-08-02 11:57           ` Linus Walleij
@ 2017-09-07 21:30             ` Woojung.Huh
  2017-09-07 21:33               ` Linus Walleij
  0 siblings, 1 reply; 20+ messages in thread
From: Woojung.Huh @ 2017-09-07 21:30 UTC (permalink / raw)
  To: linus.walleij, andrew
  Cc: festevam, sergei.shtylyov, davem, f.fainelli, netdev, fabio.estevam

> 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.
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

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-09-07 21:30             ` Woojung.Huh
@ 2017-09-07 21:33               ` Linus Walleij
  2017-09-07 21:39                 ` Florian Fainelli
  0 siblings, 1 reply; 20+ messages in thread
From: Linus Walleij @ 2017-09-07 21:33 UTC (permalink / raw)
  To: Woojung.Huh
  Cc: Andrew Lunn, Fabio Estevam, Sergei Shtylyov, David S. Miller,
	Florian Fainelli, netdev, Fabio Estevam

On Thu, Sep 7, 2017 at 11:30 PM,  <Woojung.Huh@microchip.com> wrote:
>> 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.
> 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

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-09-07 21:33               ` Linus Walleij
@ 2017-09-07 21:39                 ` Florian Fainelli
  2017-09-07 21:51                   ` Woojung.Huh
  2017-09-08 23:17                   ` Linus Walleij
  0 siblings, 2 replies; 20+ messages in thread
From: Florian Fainelli @ 2017-09-07 21:39 UTC (permalink / raw)
  To: Linus Walleij, Woojung.Huh
  Cc: Andrew Lunn, Fabio Estevam, Sergei Shtylyov, David S. Miller,
	netdev, Fabio Estevam

On 09/07/2017 02:33 PM, Linus Walleij wrote:
> On Thu, Sep 7, 2017 at 11:30 PM,  <Woojung.Huh@microchip.com> wrote:
>>> 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.
>> 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?

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?

> 
> 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.
-- 
Florian

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

* RE: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-09-07 21:39                 ` Florian Fainelli
@ 2017-09-07 21:51                   ` Woojung.Huh
  2017-09-08 19:56                     ` Florian Fainelli
  2017-09-08 23:17                   ` Linus Walleij
  1 sibling, 1 reply; 20+ messages in thread
From: Woojung.Huh @ 2017-09-07 21:51 UTC (permalink / raw)
  To: f.fainelli, linus.walleij
  Cc: andrew, festevam, sergei.shtylyov, davem, netdev, fabio.estevam

> >>> 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.
> >> 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?
> 
> 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.
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.

> This thread is actually what prompted me to write this email:
>
> https://lkml.org/lkml/2017/9/2/3
Thanks for the link.



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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-09-07 21:51                   ` Woojung.Huh
@ 2017-09-08 19:56                     ` Florian Fainelli
  2017-09-08 20:03                       ` Woojung.Huh
  0 siblings, 1 reply; 20+ messages in thread
From: Florian Fainelli @ 2017-09-08 19:56 UTC (permalink / raw)
  To: Woojung.Huh, linus.walleij
  Cc: andrew, festevam, sergei.shtylyov, davem, netdev, fabio.estevam

On 09/07/2017 02:51 PM, Woojung.Huh@microchip.com wrote:
>>>>> 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.
>>>> 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?
>>
>> 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.
> 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:

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index b6f9fa670168..67dbb7c26840 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -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);
 }


> 
>> This thread is actually what prompted me to write this email:
>>
>> https://lkml.org/lkml/2017/9/2/3
> Thanks for the link.
> 
> 


-- 
Florian

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

* RE: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-09-08 19:56                     ` Florian Fainelli
@ 2017-09-08 20:03                       ` Woojung.Huh
  0 siblings, 0 replies; 20+ messages in thread
From: Woojung.Huh @ 2017-09-08 20:03 UTC (permalink / raw)
  To: f.fainelli, linus.walleij
  Cc: andrew, festevam, sergei.shtylyov, davem, netdev, fabio.estevam,
	Bryan.Whitehead

> >> 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.
> > 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:
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index b6f9fa670168..67dbb7c26840 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -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

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

* Re: [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check
  2017-09-07 21:39                 ` Florian Fainelli
  2017-09-07 21:51                   ` Woojung.Huh
@ 2017-09-08 23:17                   ` Linus Walleij
  1 sibling, 0 replies; 20+ messages in thread
From: Linus Walleij @ 2017-09-08 23:17 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Woojung.Huh, Andrew Lunn, Fabio Estevam, Sergei Shtylyov,
	David S. Miller, netdev, Fabio Estevam

On Thu, Sep 7, 2017 at 11:39 PM, Florian Fainelli <f.fainelli@gmail.com> wrote:

> 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:

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

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

end of thread, other threads:[~2017-09-08 23:17 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-17 21:09 [PATCH net-next] mdio_bus: Remove unneeded gpiod NULL check Fabio Estevam
2017-07-17 21:21 ` Andrew Lunn
2017-07-17 23:57 ` David Miller
2017-07-18  9:56 ` Sergei Shtylyov
2017-07-18 12:39   ` Fabio Estevam
2017-07-18 12:48     ` Sergei Shtylyov
2017-07-18 12:52       ` Fabio Estevam
2017-07-18 13:02         ` Sergei Shtylyov
2017-07-18 13:09           ` Fabio Estevam
2017-07-18 13:13             ` Sergei Shtylyov
2017-07-18 13:32         ` Andrew Lunn
2017-07-19 22:37           ` Fabio Estevam
2017-08-02 11:57           ` Linus Walleij
2017-09-07 21:30             ` Woojung.Huh
2017-09-07 21:33               ` Linus Walleij
2017-09-07 21:39                 ` Florian Fainelli
2017-09-07 21:51                   ` Woojung.Huh
2017-09-08 19:56                     ` Florian Fainelli
2017-09-08 20:03                       ` Woojung.Huh
2017-09-08 23:17                   ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.