[PATCH v8 3/3] drm/tinydrm: Add devres versions of backlight_get

Jani Nikula jani.nikula at linux.intel.com
Wed Oct 11 13:56:25 UTC 2017


On Wed, 11 Oct 2017, Meghana Madhyastha <meghana.madhyastha at gmail.com> wrote:
> Add devm_backlight_get and the corresponding release
> function because some drivers use devres versions of functions
> for requiring device resources.
>
> Signed-off-by: Meghana Madhyastha <meghana.madhyastha at gmail.com>
> ---
> Changes in v8:
> -Put the devres version to backlight.c along with backlight_get.
>
>  drivers/gpu/drm/tinydrm/mi0283qt.c  |  2 +-
>  drivers/video/backlight/backlight.c | 31 +++++++++++++++++++++++++++++++
>  include/linux/backlight.h           | 16 ++++++++++++++++
>  3 files changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c b/drivers/gpu/drm/tinydrm/mi0283qt.c
> index edf9502..03fec36 100644
> --- a/drivers/gpu/drm/tinydrm/mi0283qt.c
> +++ b/drivers/gpu/drm/tinydrm/mi0283qt.c
> @@ -190,7 +190,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 1debb60..9b24dc2 100644
> --- a/drivers/video/backlight/backlight.c
> +++ b/drivers/video/backlight/backlight.c
> @@ -618,6 +618,37 @@ struct backlight_device *backlight_get(struct device *dev)
>  	return bd;
>  }
>  EXPORT_SYMBOL(backlight_get);
> +
> +static void devm_backlight_get_release(void *data)

I think that's a confusing name because of the "get", maybe just call it
devm_backlight_put?


BR,
Jani.



> +{
> +	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_get_release, bd);
> +	if (ret) {
> +		backlight_put(bd);
> +		return ERR_PTR(ret);
> +	}
> +
> +	return bd;
> +}
> +EXPORT_SYMBOL(devm_backlight_get);
>  #endif
>  
>  static void __exit backlight_class_exit(void)
> diff --git a/include/linux/backlight.h b/include/linux/backlight.h
> index 1d713b3..0bfadb6 100644
> --- a/include/linux/backlight.h
> +++ b/include/linux/backlight.h
> @@ -183,6 +183,16 @@ static inline int backlight_disable(struct backlight_device *bd)
>  	return backlight_update_status(bd);
>  }
>  
> +/**
> + ** backlight_put - Drop backlight reference
> + ** @bd: the backlight device to put
> + **/
> +static inline void backlight_put(struct backlight_device *bd)
> +{
> +	if (bd)
> +		put_device(&bd->dev);
> +}
> +
>  struct generic_bl_info {
>  	const char *name;
>  	int max_intensity;
> @@ -204,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

-- 
Jani Nikula, Intel Open Source Technology Center


More information about the dri-devel mailing list