Merge tag 'v3.10.79' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / leds / leds-pwm.c
index faf52c005e8c230ef255407294e3f44b6beb6b0b..5d64b2431415d9ea389c435850fd78851e2a86a8 100644 (file)
@@ -82,6 +82,15 @@ static inline size_t sizeof_pwm_leds_priv(int num_leds)
                      (sizeof(struct led_pwm_data) * num_leds);
 }
 
+static void led_pwm_cleanup(struct led_pwm_priv *priv)
+{
+       while (priv->num_leds--) {
+               led_classdev_unregister(&priv->leds[priv->num_leds].cdev);
+               if (priv->leds[priv->num_leds].can_sleep)
+                       cancel_work_sync(&priv->leds[priv->num_leds].work);
+       }
+}
+
 static struct led_pwm_priv *led_pwm_create_of(struct platform_device *pdev)
 {
        struct device_node *node = pdev->dev.of_node;
@@ -139,8 +148,7 @@ static struct led_pwm_priv *led_pwm_create_of(struct platform_device *pdev)
 
        return priv;
 err:
-       while (priv->num_leds--)
-               led_classdev_unregister(&priv->leds[priv->num_leds].cdev);
+       led_pwm_cleanup(priv);
 
        return NULL;
 }
@@ -200,8 +208,8 @@ static int led_pwm_probe(struct platform_device *pdev)
        return 0;
 
 err:
-       while (i--)
-               led_classdev_unregister(&priv->leds[i].cdev);
+       priv->num_leds = i;
+       led_pwm_cleanup(priv);
 
        return ret;
 }
@@ -209,13 +217,8 @@ err:
 static int led_pwm_remove(struct platform_device *pdev)
 {
        struct led_pwm_priv *priv = platform_get_drvdata(pdev);
-       int i;
 
-       for (i = 0; i < priv->num_leds; i++) {
-               led_classdev_unregister(&priv->leds[i].cdev);
-               if (priv->leds[i].can_sleep)
-                       cancel_work_sync(&priv->leds[i].work);
-       }
+       led_pwm_cleanup(priv);
 
        return 0;
 }