Skip to content

Commit 20cdba9

Browse files
Dan Murphypavelmachek
authored andcommitted
leds: flash: Add devm_* functions to the flash class
Add the missing device managed API for registration and unregistration for the LED flash class. Signed-off-by: Dan Murphy <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent 57e5c31 commit 20cdba9

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

drivers/leds/led-class-flash.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,56 @@ void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev)
327327
}
328328
EXPORT_SYMBOL_GPL(led_classdev_flash_unregister);
329329

330+
static void devm_led_classdev_flash_release(struct device *dev, void *res)
331+
{
332+
led_classdev_flash_unregister(*(struct led_classdev_flash **)res);
333+
}
334+
335+
int devm_led_classdev_flash_register_ext(struct device *parent,
336+
struct led_classdev_flash *fled_cdev,
337+
struct led_init_data *init_data)
338+
{
339+
struct led_classdev_flash **dr;
340+
int ret;
341+
342+
dr = devres_alloc(devm_led_classdev_flash_release, sizeof(*dr),
343+
GFP_KERNEL);
344+
if (!dr)
345+
return -ENOMEM;
346+
347+
ret = led_classdev_flash_register_ext(parent, fled_cdev, init_data);
348+
if (ret) {
349+
devres_free(dr);
350+
return ret;
351+
}
352+
353+
*dr = fled_cdev;
354+
devres_add(parent, dr);
355+
356+
return 0;
357+
}
358+
EXPORT_SYMBOL_GPL(devm_led_classdev_flash_register_ext);
359+
360+
static int devm_led_classdev_flash_match(struct device *dev,
361+
void *res, void *data)
362+
{
363+
struct led_classdev_flash **p = res;
364+
365+
if (WARN_ON(!p || !*p))
366+
return 0;
367+
368+
return *p == data;
369+
}
370+
371+
void devm_led_classdev_flash_unregister(struct device *dev,
372+
struct led_classdev_flash *fled_cdev)
373+
{
374+
WARN_ON(devres_release(dev,
375+
devm_led_classdev_flash_release,
376+
devm_led_classdev_flash_match, fled_cdev));
377+
}
378+
EXPORT_SYMBOL_GPL(devm_led_classdev_flash_unregister);
379+
330380
static void led_clamp_align(struct led_flash_setting *s)
331381
{
332382
u32 v, offset;

include/linux/led-class-flash.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ static inline int led_classdev_flash_register(struct device *parent,
113113
*/
114114
void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
115115

116+
int devm_led_classdev_flash_register_ext(struct device *parent,
117+
struct led_classdev_flash *fled_cdev,
118+
struct led_init_data *init_data);
119+
120+
121+
static inline int devm_led_classdev_flash_register(struct device *parent,
122+
struct led_classdev_flash *fled_cdev)
123+
{
124+
return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL);
125+
}
126+
127+
void devm_led_classdev_flash_unregister(struct device *parent,
128+
struct led_classdev_flash *fled_cdev);
129+
116130
/**
117131
* led_set_flash_strobe - setup flash strobe
118132
* @fled_cdev: the flash LED to set strobe on

0 commit comments

Comments
 (0)