Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney...
[sfrench/cifs-2.6.git] / drivers / leds / leds-gpio.c
index d2d54d62afee6b701835c1e39777fb5921cfc698..af1876a3a77c883a630f1c7765864ea28d3f0a03 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/kernel.h>
 #include <linux/leds.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/slab.h>
@@ -198,8 +199,10 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
                } else {
                        if (IS_ENABLED(CONFIG_OF) && !led.name && np)
                                led.name = np->name;
-                       if (!led.name)
-                               return ERR_PTR(-EINVAL);
+                       if (!led.name) {
+                               ret = -EINVAL;
+                               goto err;
+                       }
                }
                fwnode_property_read_string(child, "linux,default-trigger",
                                            &led.default_trigger);
@@ -217,18 +220,19 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
                if (fwnode_property_present(child, "retain-state-suspended"))
                        led.retain_state_suspended = 1;
 
-               ret = create_gpio_led(&led, &priv->leds[priv->num_leds++],
+               ret = create_gpio_led(&led, &priv->leds[priv->num_leds],
                                      dev, NULL);
                if (ret < 0) {
                        fwnode_handle_put(child);
                        goto err;
                }
+               priv->num_leds++;
        }
 
        return priv;
 
 err:
-       for (count = priv->num_leds - 2; count >= 0; count--)
+       for (count = priv->num_leds - 1; count >= 0; count--)
                delete_gpio_led(&priv->leds[count]);
        return ERR_PTR(ret);
 }