]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
leds: Allow to call led_classdev_unregister() unconditionally
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 16 Aug 2019 10:52:29 +0000 (13:52 +0300)
committerJacek Anaszewski <jacek.anaszewski@gmail.com>
Mon, 26 Aug 2019 18:03:58 +0000 (20:03 +0200)
If in the certain driver the LED is optional, and it's a majority of them,
the call of led_classdev_unregister() still requires some additional
checks.

The usual pattern on unregistering is to check for NULL, but we also check
for IS_ERR() in case device_create_with_groups() fails.

The change will reduce a burden in a lot of drivers to repeatedly check
for above conditions.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
drivers/leds/led-class.c

index 052c7571e1888eaf4345c858e684a79f8c60e4e0..647b1263c5794e1cc485447627a5b59afd566a95 100644 (file)
@@ -287,6 +287,7 @@ int led_classdev_register_ext(struct device *parent,
                ret = led_add_brightness_hw_changed(led_cdev);
                if (ret) {
                        device_unregister(led_cdev->dev);
+                       led_cdev->dev = NULL;
                        mutex_unlock(&led_cdev->led_access);
                        return ret;
                }
@@ -332,6 +333,9 @@ EXPORT_SYMBOL_GPL(led_classdev_register_ext);
  */
 void led_classdev_unregister(struct led_classdev *led_cdev)
 {
+       if (IS_ERR_OR_NULL(led_cdev->dev))
+               return;
+
 #ifdef CONFIG_LEDS_TRIGGERS
        down_write(&led_cdev->trigger_lock);
        if (led_cdev->trigger)