leds: core: add managed version of led_trigger_register
authorHeiner Kallweit <hkallweit1@gmail.com>
Sat, 2 Jan 2016 00:36:41 +0000 (01:36 +0100)
committerJacek Anaszewski <j.anaszewski@samsung.com>
Mon, 4 Jan 2016 08:57:40 +0000 (09:57 +0100)
Complementing devm_led_classdev_register add a managed version of
led_trigger_register.

I omit a managed version of led_classdev_unregister as the equivalent
devm_led_classdev_unregister isn't used in the kernel as of today.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
drivers/leds/led-triggers.c
include/linux/leds.h

index e8b1120f486d6de7289f77e378b0e2ad14e3712d..e1e933424ac9a4366a223eeb7e8ca13d4d9290e3 100644 (file)
@@ -249,6 +249,34 @@ void led_trigger_unregister(struct led_trigger *trig)
 }
 EXPORT_SYMBOL_GPL(led_trigger_unregister);
 
+static void devm_led_trigger_release(struct device *dev, void *res)
+{
+       led_trigger_unregister(*(struct led_trigger **)res);
+}
+
+int devm_led_trigger_register(struct device *dev,
+                             struct led_trigger *trig)
+{
+       struct led_trigger **dr;
+       int rc;
+
+       dr = devres_alloc(devm_led_trigger_release, sizeof(*dr),
+                         GFP_KERNEL);
+       if (!dr)
+               return -ENOMEM;
+
+       *dr = trig;
+
+       rc = led_trigger_register(trig);
+       if (rc)
+               devres_free(dr);
+       else
+               devres_add(dev, dr);
+
+       return rc;
+}
+EXPORT_SYMBOL_GPL(devm_led_trigger_register);
+
 /* Simple LED Tigger Interface */
 
 void led_trigger_event(struct led_trigger *trig,
index 088f1da02beda06d08abb07426c570edbf6c8fb9..bc1476fda96eb3206995b270e32cb54a49305eea 100644 (file)
@@ -246,6 +246,8 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
 /* Registration functions for complex triggers */
 extern int led_trigger_register(struct led_trigger *trigger);
 extern void led_trigger_unregister(struct led_trigger *trigger);
+extern int devm_led_trigger_register(struct device *dev,
+                                    struct led_trigger *trigger);
 
 extern void led_trigger_register_simple(const char *name,
                                struct led_trigger **trigger);