leds: leds-gpio: Fix multiple instances registration without 'label' property
authorFabio Estevam <fabio.estevam@freescale.com>
Thu, 4 Dec 2014 01:28:19 +0000 (02:28 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 4 Dec 2014 01:28:19 +0000 (02:28 +0100)
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.

Fixes: a43f2cbbb009 (leds: leds-gpio: Make use of device property API)
Reported-by: Jean-Michel Hautbois <jean-michel.hautbois@vodalys.com>
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Acked-by: Grant Likely <grant.likely@linaro.org>
Acked-by: Bryan Wu <cooloney@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/leds/leds-gpio.c

index b3c5d9d6a42bcd8b200fbbd0b6b7f556f97e4768..868e6fc17cbad51725412adf483cd4b2f4e8d788 100644 (file)
@@ -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,16 @@ 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 {
+                       if (IS_ENABLED(CONFIG_OF) && !led.name && np)
+                               led.name = np->name;
+                       if (!led.name)
+                               return ERR_PTR(-EINVAL);
+               }
                fwnode_property_read_string(child, "linux,default-trigger",
                                            &led.default_trigger);