Skip to contentSkip to conversation

leds: leds-gpio: Fix multiple instances registration when 'label' property is absent

PATCH Superseded Fabio Estevam 2 participants 2 messages Dec 3, 2014 LED

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: leds-gpio: Fix multiple instances registration when 'label' property is absent

From: Fabio Estevam <[email protected]>

Since commit a43f2cbbb009f96 ("leds: leds-gpio: Make use of device property API") it is no longer possible to register multiple gpio leds without passing the 'label' property.

According to Documentation/devicetree/bindings/leds/common.txt:

"Optional properties for child nodes:
- label : The label for this LED. If omitted, the label is taken from the node name (excluding the unit address)."

So retrieve the node name when the 'label' property is absent to keep the old behaviour and fix this regression.

---
 drivers/leds/leds-gpio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-gpio.c +7 -1
index fd53968..a635330 100644
@@ -170,6 +170,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
 	struct fwnode_handle *child;
 	struct gpio_leds_priv *priv;
 	int count, ret;
+	struct device_node *np;
 
 	count = device_get_child_node_count(dev);
 	if (!count)
@@ -189,7 +190,12 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
 			goto err;
 		}
 
-		fwnode_property_read_string(child, "label", &led.name);
+		np = of_node(child);
+
+		if (fwnode_property_present(child, "label"))
+			fwnode_property_read_string(child, "label", &led.name);
+		else
+			led.name = np->name;
 		fwnode_property_read_string(child, "linux,default-trigger",
 					    &led.default_trigger);
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 34 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Since commit a43f2cbbb009f96 ("leds: leds-gpio: Make use of device property API") it is no longer possible to register multiple gpio leds without passing the 'label' property.

According to Documentation/devicetree/bindings/leds/common.txt:

"Optional properties for child nodes:
- label : The label for this LED. If omitted, the label is taken from the node name (excluding the unit address)."

So retrieve the node name when the 'label' property is absent to keep the old behaviour and fix this regression.

---
 drivers/leds/leds-gpio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/leds/leds-gpio.c +1 -0
index fd53968..a635330 100644
@@ -170,6 +170,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
        struct fwnode_handle *child;
        struct gpio_leds_priv *priv;
        int count, ret;
+       struct device_node *np;
 
        count = device_get_child_node_count(dev);
        if (!count)

drivers/leds/leds-gpio.c static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) · line 198

Quoted 10 lines
drivers/leds/leds-gpio.c +6 -1
@@ -189,7 +190,12 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
                        goto err;
                }
 
-               fwnode_property_read_string(child, "label", &led.name);
+               np = of_node(child);
+
+               if (fwnode_property_present(child, "label"))
+                       fwnode_property_read_string(child, "label", &led.name);
+               else
+                       led.name = np->name;

np will be NULL when ACPI is used and that will break this driver. Instead you need to use the construct:

                 fwnode_property_read_string(child, "label", &led.name);
                 if (IS_ENABLED(CONFIG_OF) && !led.name && np)
                         led.name = np->name;
                 if (!led.name)
                         error;
Quoted 6 lines
drivers/leds/leds-gpio.c +0 -1
                fwnode_property_read_string(child, "linux,default-trigger",
                                            &led.default_trigger);
 
--

1.9.1