Skip to contentSkip to conversation

gpio: fix "gpio-line-names" property retrieval

PATCH Superseded Christophe Leroy 2 participants 2 messages Dec 15, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: fix "gpio-line-names" property retrieval

Following commit 9427ecbed46cc ("gpio: Rework of_gpiochip_set_names() to use device property accessors"), "gpio-line-names" DT property is not retrieved anymore when chip->parent is not set by the driver.

This patch fixes that.

Fixes 9427ecbed46cc ("gpio: Rework of_gpiochip_set_names()

to use device property accessors")

---
 drivers/gpio/gpiolib-devprop.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib-devprop.c +10 -6
index 27f383bda7d9..310dbc451a85 100644
@@ -30,20 +30,24 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip)
 	struct gpio_device *gdev = chip->gpiodev;
 	const char **names;
 	int ret, i;
+	struct device *dev;
 
-	if (!chip->parent) {
+	if (chip->parent) {
+		dev = chip->parent;
+	} else if (gdev->dev.of_node) {
+		dev = &gdev->dev;
+	} else {
 		dev_warn(&gdev->dev, "GPIO chip parent is NULL\n");
 		return;
 	}
 
-	ret = device_property_read_string_array(chip->parent, "gpio-line-names",
+	ret = device_property_read_string_array(dev, "gpio-line-names",
 						NULL, 0);
 	if (ret < 0)
 		return;
 
 	if (ret != gdev->ngpio) {
-		dev_warn(chip->parent,
-			 "names %d do not match number of GPIOs %d\n", ret,
+		dev_warn(dev, "names %d do not match number of GPIOs %d\n", ret,
 			 gdev->ngpio);
 		return;
 	}
@@ -52,10 +56,10 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip)
 	if (!names)
 		return;
 
-	ret = device_property_read_string_array(chip->parent, "gpio-line-names",
+	ret = device_property_read_string_array(dev, "gpio-line-names",
 						names, gdev->ngpio);
 	if (ret < 0) {
-		dev_warn(chip->parent, "failed to read GPIO line names\n");
+		dev_warn(dev, "failed to read GPIO line names\n");
 		kfree(names);
 		return;
 	}
Signature · 1 line
2.13.3
#1 lore raw
Quoted 3 lines · Christophe Leroy

Following commit 9427ecbed46cc ("gpio: Rework of_gpiochip_set_names() to use device property accessors"), "gpio-line-names" DT property is not retrieved anymore when chip->parent is not set by the driver.

Thanks for taking care of this and sorry about the breakage.

I think this changelog should have few more words about the reason it started to fail.

Quoted 4 lines

This patch fixes that.

Fixes 9427ecbed46cc ("gpio: Rework of_gpiochip_set_names()

to use device property accessors")

Don't wrap the Fixes line.

Quoted 12 lines
---
 drivers/gpio/gpiolib-devprop.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib-devprop.c +0 -0
index 27f383bda7d9..310dbc451a85 100644
@@ -30,20 +30,24 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip)
 	struct gpio_device *gdev = chip->gpiodev;

drivers/gpio/gpiolib-devprop.c void devprop_gpiochip_set_names(struct gpio_chip *chip) · line 39

Quoted 10 lines
drivers/gpio/gpiolib-devprop.c +6 -1
 	const char **names;
 	int ret, i;
+	struct device *dev;
 
-	if (!chip->parent) {
+	if (chip->parent) {
+		dev = chip->parent;
+	} else if (gdev->dev.of_node) {
+		dev = &gdev->dev;
+	} else {

I wonder if it would be better to change devprop_gpiochip_set_names() take struct fwnode_handle as second parameter and use that instead of chip->parent below? The reason why this happens now is that not all DT enabled drivers seem to set chip->parent (which I guess is pretty valid thing to do) but they still set of_node accordingly.

Quoted 32 lines
drivers/gpio/gpiolib-devprop.c +4 -5
 		dev_warn(&gdev->dev, "GPIO chip parent is NULL\n");
 		return;
 	}
 
-	ret = device_property_read_string_array(chip->parent, "gpio-line-names",
+	ret = device_property_read_string_array(dev, "gpio-line-names",
 						NULL, 0);
 	if (ret < 0)
 		return;
 
 	if (ret != gdev->ngpio) {
-		dev_warn(chip->parent,
-			 "names %d do not match number of GPIOs %d\n", ret,
+		dev_warn(dev, "names %d do not match number of GPIOs %d\n", ret,
 			 gdev->ngpio);
 		return;
 	}
@@ -52,10 +56,10 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip)
 	if (!names)
 		return;
 
-	ret = device_property_read_string_array(chip->parent, "gpio-line-names",
+	ret = device_property_read_string_array(dev, "gpio-line-names",
 						names, gdev->ngpio);
 	if (ret < 0) {
-		dev_warn(chip->parent, "failed to read GPIO line names\n");
+		dev_warn(dev, "failed to read GPIO line names\n");
 		kfree(names);
 		return;
 	}
Signature · 1 line
2.13.3