* [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc
@ 2014-01-07 6:05 Xiubo Li
2014-01-07 7:14 ` Joe Perches
2014-01-07 8:01 ` Dmitry Torokhov
0 siblings, 2 replies; 5+ messages in thread
From: Xiubo Li @ 2014-01-07 6:05 UTC (permalink / raw)
To: thierry.reding; +Cc: linux-pwm, linux-kernel, Xiubo Li
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;
--
1.8.4
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc
2014-01-07 6:05 [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc Xiubo Li
@ 2014-01-07 7:14 ` Joe Perches
2014-01-07 7:36 ` Li.Xiubo
2014-01-07 8:01 ` Dmitry Torokhov
1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2014-01-07 7:14 UTC (permalink / raw)
To: Xiubo Li; +Cc: thierry.reding, linux-pwm, linux-kernel
On Tue, 2014-01-07 at 14:05 +0800, Xiubo Li wrote:
> Use devm_kzalloc instead of kzalloc to free automatically and make
> the cleanup paths simpler and the code slightly shorter.
[]
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
[]
> @@ -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);
There is a devm_kcalloc and this should likely use it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc
2014-01-07 7:14 ` Joe Perches
@ 2014-01-07 7:36 ` Li.Xiubo
0 siblings, 0 replies; 5+ messages in thread
From: Li.Xiubo @ 2014-01-07 7:36 UTC (permalink / raw)
To: Joe Perches; +Cc: thierry.reding, linux-pwm, linux-kernel
> > Use devm_kzalloc instead of kzalloc to free automatically and make
> > the cleanup paths simpler and the code slightly shorter.
> []
> > diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> []
> > @@ -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);
>
> There is a devm_kcalloc and this should likely use it.
>
Yes, I will use it.
Thanks,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc
2014-01-07 6:05 [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc Xiubo Li
2014-01-07 7:14 ` Joe Perches
@ 2014-01-07 8:01 ` Dmitry Torokhov
2014-01-08 4:58 ` Li.Xiubo
1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2014-01-07 8:01 UTC (permalink / raw)
To: Xiubo Li; +Cc: thierry.reding, linux-pwm, linux-kernel
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
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc
2014-01-07 8:01 ` Dmitry Torokhov
@ 2014-01-08 4:58 ` Li.Xiubo
0 siblings, 0 replies; 5+ messages in thread
From: Li.Xiubo @ 2014-01-08 4:58 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: thierry.reding, linux-pwm, linux-kernel
> > 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.
>
Yes, for now they are.
Thanks.
--
Best Regards,
Xiubo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-01-08 4:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-07 6:05 [PATCH] pwm: core: Use devm_kzalloc instead of kzalloc Xiubo Li
2014-01-07 7:14 ` Joe Perches
2014-01-07 7:36 ` Li.Xiubo
2014-01-07 8:01 ` Dmitry Torokhov
2014-01-08 4:58 ` Li.Xiubo
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