mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Xiubo Li <Li.Xiubo@freescale.com>
Cc: thierry.reding@gmail.com, linux-pwm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc
Date: Tue, 7 Jan 2014 00:01:27 -0800	[thread overview]
Message-ID: <20140107080127.GD20074@core.coreip.homeip.net> (raw)
In-Reply-To: <1389074700-1825-1-git-send-email-Li.Xiubo@freescale.com>

Hi Xiubo,

On Tue, Jan 07, 2014 at 02:05:00PM +0800, Xiubo Li wrote:
> Use devm_kzalloc instead of kzalloc to free automatically and make
> the cleanup paths simpler and the code slightly shorter.
> 
> Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
> ---
>  drivers/pwm/core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 2ca9504..74c9f9a 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -80,7 +80,6 @@ static void free_pwms(struct pwm_chip *chip)
>  
>  	bitmap_clear(allocated_pwms, chip->base, chip->npwm);
>  
> -	kfree(chip->pwms);
>  	chip->pwms = NULL;
>  }
>  
> @@ -245,7 +244,9 @@ int pwmchip_add(struct pwm_chip *chip)
>  	if (ret < 0)
>  		goto out;
>  
> -	chip->pwms = kzalloc(chip->npwm * sizeof(*pwm), GFP_KERNEL);
> +	chip->pwms = devm_kzalloc(chip->dev,
> +				  chip->npwm * sizeof(*pwm),
> +				  GFP_KERNEL);
>  	if (!chip->pwms) {
>  		ret = -ENOMEM;
>  		goto out;

Is it guaranteed that pwmchip_add()/free_pwms() will only be called in
probe() and remove() paths? It is probably safe assumption, but maybe it
should be mentioned in comments now that we definitely have this
restricion.

Thanks.

-- 
Dmitry

  parent reply	other threads:[~2014-01-07  8:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-07  6:05 Xiubo Li
2014-01-07  7:14 ` Joe Perches
2014-01-07  7:36   ` Li.Xiubo
2014-01-07  8:01 ` Dmitry Torokhov [this message]
2014-01-08  4:58   ` Li.Xiubo

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=20140107080127.GD20074@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=Li.Xiubo@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --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

Powered by JetHome