linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Flavio Suligoi <f.suligoi@asem.it>,
	Thierry Reding <thierry.reding@gmail.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org,
	Jonathan Corbet <corbet@lwn.net>,
	Lee Jones <lee.jones@linaro.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>
Subject: Re: [PATCH v2 7/7] pwm: core: Simplify some devm_*pwm*() functions
Date: Sun, 6 Jun 2021 23:45:12 +0200	[thread overview]
Message-ID: <20210606214512.36ntagggat7wbhvh@pengutronix.de> (raw)
In-Reply-To: <20210531194947.10770-7-andriy.shevchenko@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 3464 bytes --]

Hello Andy,

On Mon, May 31, 2021 at 10:49:47PM +0300, Andy Shevchenko wrote:
> Use devm_add_action_or_reset() instead of devres_alloc() and
> devres_add(), which works the same. This will simplify the
> code. There is no functional changes.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: new patch
>  drivers/pwm/core.c | 60 +++++++++++++++++++---------------------------
>  1 file changed, 25 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 6d4410bd9793..9f643414676b 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -1059,9 +1059,9 @@ void pwm_put(struct pwm_device *pwm)
>  }
>  EXPORT_SYMBOL_GPL(pwm_put);
>  
> -static void devm_pwm_release(struct device *dev, void *res)
> +static void devm_pwm_release(void *pwm)
>  {
> -	pwm_put(*(struct pwm_device **)res);
> +	pwm_put(pwm);
>  }
>  
>  /**
> @@ -1077,19 +1077,16 @@ static void devm_pwm_release(struct device *dev, void *res)
>   */
>  struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id)
>  {
> -	struct pwm_device **ptr, *pwm;
> -
> -	ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return ERR_PTR(-ENOMEM);
> +	struct pwm_device *pwm;
> +	int ret;
>  
>  	pwm = pwm_get(dev, con_id);
> -	if (!IS_ERR(pwm)) {
> -		*ptr = pwm;
> -		devres_add(dev, ptr);
> -	} else {
> -		devres_free(ptr);
> -	}
> +	if (IS_ERR(pwm))
> +		return pwm;
> +
> +	ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return pwm;
>  }
> @@ -1110,19 +1107,16 @@ EXPORT_SYMBOL_GPL(devm_pwm_get);
>  struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
>  				   const char *con_id)
>  {
> -	struct pwm_device **ptr, *pwm;
> -
> -	ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return ERR_PTR(-ENOMEM);
> +	struct pwm_device *pwm;
> +	int ret;
>  
>  	pwm = of_pwm_get(dev, np, con_id);
> -	if (!IS_ERR(pwm)) {
> -		*ptr = pwm;
> -		devres_add(dev, ptr);
> -	} else {
> -		devres_free(ptr);
> -	}
> +	if (IS_ERR(pwm))
> +		return pwm;
> +
> +	ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
>  	return pwm;
>  }
> @@ -1144,23 +1138,19 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
>  				       struct fwnode_handle *fwnode,
>  				       const char *con_id)
>  {
> -	struct pwm_device **ptr, *pwm = ERR_PTR(-ENODEV);
> -
> -	ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL);
> -	if (!ptr)
> -		return ERR_PTR(-ENOMEM);
> +	struct pwm_device *pwm = ERR_PTR(-ENODEV);
> +	int ret;
>  
>  	if (is_of_node(fwnode))
>  		pwm = of_pwm_get(dev, to_of_node(fwnode), con_id);
>  	else if (is_acpi_node(fwnode))
>  		pwm = acpi_pwm_get(fwnode);
> +	if (IS_ERR(pwm))
> +		return pwm;
>  
> -	if (!IS_ERR(pwm)) {
> -		*ptr = pwm;
> -		devres_add(dev, ptr);
> -	} else {
> -		devres_free(ptr);
> -	}
> +	ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
> +	if (ret)
> +		return ERR_PTR(ret);
>  

Another nice one:

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2021-06-06 21:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31 19:49 [PATCH v2 1/7] docs: firmware-guide: ACPI: Add a PWM example Andy Shevchenko
2021-05-31 19:49 ` [PATCH v2 2/7] pwm: core: Always require PWM flags to be provided Andy Shevchenko
2021-06-06 21:30   ` Uwe Kleine-König
2021-06-07  9:02     ` Andy Shevchenko
2021-06-07  9:53       ` Uwe Kleine-König
2021-06-07 10:15         ` Andy Shevchenko
2021-06-07 10:21           ` Andy Shevchenko
2021-06-07 11:49             ` Andy Shevchenko
2021-06-07 14:11               ` Uwe Kleine-König
2021-05-31 19:49 ` [PATCH v2 3/7] pwm: core: Convert to use fwnode for matching Andy Shevchenko
2021-05-31 19:49 ` [PATCH v2 4/7] pwm: core: Reuse fwnode_to_pwmchip() in ACPI case Andy Shevchenko
2021-05-31 19:49 ` [PATCH v2 5/7] pwm: core: Unify fwnode checks in the module Andy Shevchenko
2021-05-31 19:49 ` [PATCH v2 6/7] pwm: core: Remove unused devm_pwm_put() Andy Shevchenko
2021-06-06 21:40   ` Uwe Kleine-König
2021-05-31 19:49 ` [PATCH v2 7/7] pwm: core: Simplify some devm_*pwm*() functions Andy Shevchenko
2021-06-06 21:45   ` Uwe Kleine-König [this message]

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=20210606214512.36ntagggat7wbhvh@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=f.suligoi@asem.it \
    --cc=lee.jones@linaro.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=thierry.reding@gmail.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).