diff mbox series

Accept partial 'gpio-line-names' property.

Message ID 1538141923-6480-1-git-send-email-christophe.blaess@logilin.fr
State New
Headers show
Series Accept partial 'gpio-line-names' property. | expand

Commit Message

Christophe Blaess Sept. 28, 2018, 1:38 p.m. UTC
Documentation/devicetree/bindings/gpio/gpio.txt says: "The names are
assigned starting from line offset 0 from left to right from the
passed array. An incomplete array (where the number of passed named
are less than ngpios) will still be used up until the last provided
valid line index". This patch makes it actually work this way.


Signed-off-by: Christophe Blaess <christophe.blaess@logilin.fr>
Signed-off-by: Patrick Boettcher <p@yai.se>
---
 drivers/gpio/gpiolib-devprop.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Comments

Linus Walleij Oct. 1, 2018, 11:14 a.m. UTC | #1
On Fri, Sep 28, 2018 at 3:38 PM Christophe Blaess
<christophe.blaess@logilin.fr> wrote:

> Documentation/devicetree/bindings/gpio/gpio.txt says: "The names are
> assigned starting from line offset 0 from left to right from the
> passed array. An incomplete array (where the number of passed named
> are less than ngpios) will still be used up until the last provided
> valid line index". This patch makes it actually work this way.
>
>
> Signed-off-by: Christophe Blaess <christophe.blaess@logilin.fr>
> Signed-off-by: Patrick Boettcher <p@yai.se>

Sweet, that's a very nice patch! Applied.

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-devprop.c b/drivers/gpio/gpiolib-devprop.c
index f748aa3..34bfcf7 100644
--- a/drivers/gpio/gpiolib-devprop.c
+++ b/drivers/gpio/gpiolib-devprop.c
@@ -32,32 +32,29 @@  void devprop_gpiochip_set_names(struct gpio_chip *chip,
 	struct gpio_device *gdev = chip->gpiodev;
 	const char **names;
 	int ret, i;
+	int count;
 
-	ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
-						NULL, 0);
-	if (ret < 0)
+	count = fwnode_property_read_string_array(fwnode, "gpio-line-names",
+						  NULL, 0);
+	if (count < 0)
 		return;
 
-	if (ret != gdev->ngpio) {
-		dev_warn(&gdev->dev,
-			 "names %d do not match number of GPIOs %d\n", ret,
-			 gdev->ngpio);
-		return;
-	}
+	if (count > gdev->ngpio)
+		count = gdev->ngpio;
 
-	names = kcalloc(gdev->ngpio, sizeof(*names), GFP_KERNEL);
+	names = kcalloc(count, sizeof(*names), GFP_KERNEL);
 	if (!names)
 		return;
 
 	ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
-						names, gdev->ngpio);
+						names, count);
 	if (ret < 0) {
 		dev_warn(&gdev->dev, "failed to read GPIO line names\n");
 		kfree(names);
 		return;
 	}
 
-	for (i = 0; i < gdev->ngpio; i++)
+	for (i = 0; i < count; i++)
 		gdev->descs[i].name = names[i];
 
 	kfree(names);