These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / leds / leds-gpio.c
index 15eb3f8..5db4515 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>
@@ -191,15 +192,17 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
                        goto err;
                }
 
-               np = of_node(child);
+               np = to_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);
+                       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);
 }
@@ -287,9 +291,22 @@ static int gpio_led_remove(struct platform_device *pdev)
        return 0;
 }
 
+static void gpio_led_shutdown(struct platform_device *pdev)
+{
+       struct gpio_leds_priv *priv = platform_get_drvdata(pdev);
+       int i;
+
+       for (i = 0; i < priv->num_leds; i++) {
+               struct gpio_led_data *led = &priv->leds[i];
+
+               gpio_led_set(&led->cdev, LED_OFF);
+       }
+}
+
 static struct platform_driver gpio_led_driver = {
        .probe          = gpio_led_probe,
        .remove         = gpio_led_remove,
+       .shutdown       = gpio_led_shutdown,
        .driver         = {
                .name   = "leds-gpio",
                .of_match_table = of_gpio_leds_match,