dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Meghana Madhyastha <meghana.madhyastha@gmail.com>,
	daniel@ffwll.ch, noralf@tronnes.org,
	outreachy-kernel@googlegroups.com,
	dri-devel@lists.freedesktop.org, daniel.thompson@linaro.org
Subject: Re: [PATCH v8 3/3] drm/tinydrm: Add devres versions of backlight_get
Date: Wed, 11 Oct 2017 16:56:25 +0300	[thread overview]
Message-ID: <87tvz5pz3q.fsf@intel.com> (raw)
In-Reply-To: <6dd8ab4eb88a75613a7bd69c9ff7278f03dd6ea4.1507714297.git.meghana.madhyastha@gmail.com>

On Wed, 11 Oct 2017, Meghana Madhyastha <meghana.madhyastha@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@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
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-10-11 13:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11 10:06 [PATCH v8 0/3] Move backlight helper functions from tinydrm-helpers to linux/backlight Meghana Madhyastha
2017-10-11 10:09 ` [PATCH v8 1/3] drm/tinydrm: Move helper functions from tinydrm-helpers to backlight.h Meghana Madhyastha
2017-10-11 10:13 ` [PATCH v8 2/3] drm/tinydrm: Move tinydrm_of_find_backlight to backlight.c Meghana Madhyastha
2017-10-11 10:15 ` [PATCH v8 3/3] drm/tinydrm: Add devres versions of backlight_get Meghana Madhyastha
2017-10-11 13:56   ` Jani Nikula [this message]
2017-10-11 14:18     ` Meghana Madhyastha
2017-10-11 15:07       ` Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tvz5pz3q.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=daniel.thompson@linaro.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=meghana.madhyastha@gmail.com \
    --cc=noralf@tronnes.org \
    --cc=outreachy-kernel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).