Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <dmurphy@ti.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>

authored by

Dan Murphy and committed by
Pavel
20cdba9d 57e5c31e

+64
+50
drivers/leds/led-class-flash.c
··· 327 327 } 328 328 EXPORT_SYMBOL_GPL(led_classdev_flash_unregister); 329 329 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 + 330 380 static void led_clamp_align(struct led_flash_setting *s) 331 381 { 332 382 u32 v, offset;
+14
include/linux/led-class-flash.h
··· 113 113 */ 114 114 void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev); 115 115 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 + 116 130 /** 117 131 * led_set_flash_strobe - setup flash strobe 118 132 * @fled_cdev: the flash LED to set strobe on