2020-09-16 17:52:04

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH next] gpiolib: check for parent device in devprop_gpiochip_set_names()

From: Bartosz Golaszewski <[email protected]>

It's possible for a GPIO chip to not have a parent device (whose
properties we inspect for 'gpio-line-names'). In this case we should
simply return from devprop_gpiochip_set_names(). Add an appropriate
check for this use-case.

Fixes: 7cba1a4d5e16 ("gpiolib: generalize devprop_gpiochip_set_names() for device properties")
Reported-by: Anders Roxell <[email protected]>
Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/gpio/gpiolib.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b7b608ef9..ac2c77edc 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -375,6 +375,9 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
int ret, i;
int count;

+ if (!dev)
+ return 0;
+
count = device_property_string_array_count(dev, "gpio-line-names");
if (count < 0)
return 0;
--
2.26.1


2020-09-16 18:38:55

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH next] gpiolib: check for parent device in devprop_gpiochip_set_names()

On Wed, Sep 16, 2020 at 4:29 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Wed, Sep 16, 2020 at 03:43:27PM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <[email protected]>
> >
> > It's possible for a GPIO chip to not have a parent device (whose
> > properties we inspect for 'gpio-line-names'). In this case we should
> > simply return from devprop_gpiochip_set_names(). Add an appropriate
> > check for this use-case.
>
> Ah, nice!
> Can we also add a small comment in the code, b/c w/o it I would stumble over
> and eager to remove looks-as-unneeded check?
> Reviewed-by: Andy Shevchenko <[email protected]>

Sure, I'll make a v2 then.

Bart

2020-09-16 20:48:59

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH next] gpiolib: check for parent device in devprop_gpiochip_set_names()

On Wed, Sep 16, 2020 at 03:43:27PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <[email protected]>
>
> It's possible for a GPIO chip to not have a parent device (whose
> properties we inspect for 'gpio-line-names'). In this case we should
> simply return from devprop_gpiochip_set_names(). Add an appropriate
> check for this use-case.

Ah, nice!
Can we also add a small comment in the code, b/c w/o it I would stumble over
and eager to remove looks-as-unneeded check?
Reviewed-by: Andy Shevchenko <[email protected]>

> Fixes: 7cba1a4d5e16 ("gpiolib: generalize devprop_gpiochip_set_names() for device properties")
> Reported-by: Anders Roxell <[email protected]>
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/gpio/gpiolib.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index b7b608ef9..ac2c77edc 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -375,6 +375,9 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
> int ret, i;
> int count;
>
> + if (!dev)
> + return 0;
> +
> count = device_property_string_array_count(dev, "gpio-line-names");
> if (count < 0)
> return 0;
> --
> 2.26.1
>

--
With Best Regards,
Andy Shevchenko


2020-09-16 22:44:29

by Anders Roxell

[permalink] [raw]
Subject: Re: [PATCH next] gpiolib: check for parent device in devprop_gpiochip_set_names()

On Wed, 16 Sep 2020 at 16:47, Bartosz Golaszewski <[email protected]> wrote:
>
> On Wed, Sep 16, 2020 at 4:29 PM Andy Shevchenko
> <[email protected]> wrote:
> >
> > On Wed, Sep 16, 2020 at 03:43:27PM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <[email protected]>
> > >
> > > It's possible for a GPIO chip to not have a parent device (whose
> > > properties we inspect for 'gpio-line-names'). In this case we should
> > > simply return from devprop_gpiochip_set_names(). Add an appropriate
> > > check for this use-case.
> >
> > Ah, nice!
> > Can we also add a small comment in the code, b/c w/o it I would stumble over
> > and eager to remove looks-as-unneeded check?
> > Reviewed-by: Andy Shevchenko <[email protected]>

Tested-by: Anders Roxell <[email protected]>