Skip to contentSkip to conversation

gpiolib: check for parent device in devprop_gpiochip_set_names()

PATCH Superseded Bartosz Golaszewski 3 participants 4 messages Sep 16, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 drivers/gpio/gpiolib.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpiolib.c +3 -0
index b7b608ef9..ac2c77edc 100644
@@ -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;
Signature · 1 line
2.26.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Bartosz Golaszewski

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?

Quoted 24 lines
Fixes 7cba1a4d5e16 ("gpiolib: generalize devprop_gpiochip_set_names() for device properties")
---
 drivers/gpio/gpiolib.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpiolib.c +3 -0
index b7b608ef9..ac2c77edc 100644
@@ -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;
Signature · 1 line
2.26.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski

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.

Quoted 4 lines

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?

Sure, I'll make a v2 then.

Bart

Tested-by
#3 lore raw
Quoted 12 lines · Bartosz Golaszewski
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski

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.

Quoted 4 lines
Quoted 4 lines

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?