[PATCH v9 3/5] leds: Add managed API to get a LED from a device driver

Pavel Machek pavel at ucw.cz
Sun Oct 13 12:09:52 UTC 2019


Hi!

> If the LED is acquired by a consumer device with devm_led_get(), it is
> automatically released when the device is detached.
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
> Acked-by: Pavel Machek <pavel at ucw.cz>
> ---
>  drivers/leds/led-class.c | 49 ++++++++++++++++++++++++++++++++++++++++
>  include/linux/leds.h     |  2 ++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
> index 1d1f1d546dc7..639224392ffa 100644
> --- a/drivers/leds/led-class.c
> +++ b/drivers/leds/led-class.c
> @@ -264,6 +264,55 @@ void led_put(struct led_classdev *led_cdev)
>  }
>  EXPORT_SYMBOL_GPL(led_put);
>  
> +static void devm_led_release(struct device *dev, void *res)
> +{
> +	struct led_classdev **p = res;
> +
> +	led_put(*p);
> +}
> +
> +/**
> + * devm_of_led_get - Resource-managed request of a LED device
> + * @dev:	LED consumer
> + * @index:	index of the LED to obtain in the consumer
> + *
> + * The device node of the device is parse to find the request LED device.
> + * The LED device returned from this function is automatically released
> + * on driver detach.
> + *
> + * @return a pointer to a LED device or ERR_PTR(errno) on failure.
> + */
> +struct led_classdev *__must_check devm_of_led_get(struct device *dev,
> +						  int index)
> +{
> +	struct led_classdev *led;
> +	struct led_classdev **dr;
> +
> +	if (!dev)
> +		return ERR_PTR(-EINVAL);
> +
> +	/* Consummer not using device tree? */

Typo "consumer". I may fix it before applying the patch.

Best regards,
									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20191013/810e3326/attachment.sig>


More information about the dri-devel mailing list