[Outreachy kernel] [PATCH v13 3/3] drm/tinydrm: Add devres versions of backlight_get
Sean Paul
seanpaul at chromium.org
Fri Oct 13 20:30:05 UTC 2017
On Fri, Oct 13, 2017 at 04:12:55PM +0530, Meghana Madhyastha wrote:
> Add devm_backlight_get and the corresponding release
> function because some drivers use devres versions of functions
> for requiring device resources.
>
This patch looks fine, just update the names to be consistent with the previous
version and account for backlight_put not being present.
Sean
> Signed-off-by: Meghana Madhyastha <meghana.madhyastha at gmail.com>
> ---
> Changes in v13:
> -Add devm_backlight_put to backlight.c
>
> drivers/gpu/drm/tinydrm/mi0283qt.c | 2 +-
> drivers/video/backlight/backlight.c | 31 +++++++++++++++++++++++++++++++
> include/linux/backlight.h | 6 ++++++
> 3 files changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c b/drivers/gpu/drm/tinydrm/mi0283qt.c
> index a932185..e3e7583 100644
> --- a/drivers/gpu/drm/tinydrm/mi0283qt.c
> +++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
> @@ -189,7 +189,7 @@ static int mi0283qt_probe(struct spi_device *spi)
> if (IS_ERR(mipi->regulator))
> return PTR_ERR(mipi->regulator);
>
> - mipi->backlight = backlight_get(dev);
> + mipi->backlight = devm_backlight_get(dev);
> if (IS_ERR(mipi->backlight))
> return PTR_ERR(mipi->backlight);
>
> diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
> index c4e94d0..b6c505a 100644
> --- a/drivers/video/backlight/backlight.c
> +++ b/drivers/video/backlight/backlight.c
> @@ -617,6 +617,37 @@ struct backlight_device *backlight_get(struct device *dev)
> }
> EXPORT_SYMBOL(backlight_get);
>
> +static void devm_backlight_put(void *data)
> +{
> + backlight_put(data);
> +}
> +
> +/**
> + * devm_backlight_get - Resource-managed backlight_get()
> + * @dev: Device
> + *
> + * Device managed version of backlight_get(). The reference on the backlight
> + * device is automatically dropped on driver detach.
> + */
> +struct backlight_device *devm_backlight_get(struct device *dev)
> +{
> + struct backlight_device *bd;
> + int ret;
> +
> + bd = backlight_get(dev);
> + if (!bd)
> + return NULL;
> +
> + ret = devm_add_action(dev, devm_backlight_put, bd);
> + if (ret) {
> + backlight_put(bd);
> + return ERR_PTR(ret);
> + }
> +
> + return bd;
> +}
> +EXPORT_SYMBOL(devm_backlight_get);
> +
> static void __exit backlight_class_exit(void)
> {
> class_destroy(backlight_class);
> diff --git a/include/linux/backlight.h b/include/linux/backlight.h
> index 987a6d7..8db9ba9 100644
> --- a/include/linux/backlight.h
> +++ b/include/linux/backlight.h
> @@ -214,11 +214,17 @@ of_find_backlight_by_node(struct device_node *node)
>
> #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
> struct backlight_device *backlight_get(struct device *dev);
> +struct backlight_device *devm_backlight_get(struct device *dev);
> #else
> static inline struct backlight_device *backlight_get(struct device *dev)
> {
> return NULL;
> }
> +
> +static inline struct backlight_device *devm_backlight_get(struct device *dev)
> +{
> + return NULL;
> +}
> #endif
>
> #endif
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe at googlegroups.com.
> To post to this group, send email to outreachy-kernel at googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/4b1acbfbddd2a123001e035a62801456891276d5.1507890285.git.meghana.madhyastha%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
Sean Paul, Software Engineer, Google / Chromium OS
More information about the dri-devel
mailing list