diff options
author | Heiner Kallweit <hkallweit1@gmail.com> | 2016-01-02 01:36:41 +0100 |
---|---|---|
committer | Jacek Anaszewski <j.anaszewski@samsung.com> | 2016-01-04 09:57:40 +0100 |
commit | 9534cc31dda2bb129480ce2db92bf7bc1ef470ed (patch) | |
tree | 7db0ea367e477eccad2f0a3fbb38df2fe783040e /drivers | |
parent | 1259efaab84fbc0a307477e0d2734793aa556814 (diff) |
leds: core: add managed version of led_trigger_register
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/leds/led-triggers.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index e8b1120f486d..e1e933424ac9 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -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, |