diff mbox

[v3] clk: mvebu/clk-cpu.c: fix memory leakage

Message ID 20130115184423.GC7211@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Cong Ding Jan. 15, 2013, 6:44 p.m. UTC
the variable cpuclk and clk_name should be properly freed when error happens.

Signed-off-by: Cong Ding <dinggnu@gmail.com>
Acked-by: Jason Cooper <jason@lakedaemon.net>
---
 drivers/clk/mvebu/clk-cpu.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Gregory CLEMENT Jan. 15, 2013, 8:46 p.m. UTC | #1
On 01/15/2013 07:44 PM, Cong Ding wrote:
> the variable cpuclk and clk_name should be properly freed when error happens.
Dear Cong Ding,

Thanks for you efforts!
I am happy with this patch and I tested it on the Armada XP DB board, so
you can now add my:

Acked-by: Gregory CLEMENT <gregory.clement@free-electrons.com>

Mike,

could you take this patch for 3.8-rc fixes?

If you prefer, Jason agrees to take it, but you probably didn't notice it,
because he uses your former(and no more valid) email when he wrote this.

Thanks,

Gregory

> 
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> Acked-by: Jason Cooper <jason@lakedaemon.net>
> ---
>  drivers/clk/mvebu/clk-cpu.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c
> index ff004578..9dd2551 100644
> --- a/drivers/clk/mvebu/clk-cpu.c
> +++ b/drivers/clk/mvebu/clk-cpu.c
> @@ -124,7 +124,7 @@ void __init of_cpu_clk_setup(struct device_node *node)
>  
>  	clks = kzalloc(ncpus * sizeof(*clks), GFP_KERNEL);
>  	if (WARN_ON(!clks))
> -		return;
> +		goto clks_out;
>  
>  	for_each_node_by_type(dn, "cpu") {
>  		struct clk_init_data init;
> @@ -134,11 +134,11 @@ void __init of_cpu_clk_setup(struct device_node *node)
>  		int cpu, err;
>  
>  		if (WARN_ON(!clk_name))
> -			return;
> +			goto bail_out;
>  
>  		err = of_property_read_u32(dn, "reg", &cpu);
>  		if (WARN_ON(err))
> -			return;
> +			goto bail_out;
>  
>  		sprintf(clk_name, "cpu%d", cpu);
>  		parent_clk = of_clk_get(node, 0);
> @@ -167,6 +167,9 @@ void __init of_cpu_clk_setup(struct device_node *node)
>  	return;
>  bail_out:
>  	kfree(clks);
> +	while(ncpus--)
> +		kfree(cpuclk[ncpus].clk_name);
> +clks_out:
>  	kfree(cpuclk);
>  }
>  
>
Jason Cooper Jan. 15, 2013, 8:57 p.m. UTC | #2
On Tue, Jan 15, 2013 at 09:46:03PM +0100, Gregory CLEMENT wrote:
> If you prefer, Jason agrees to take it, but you probably didn't notice it,
> because he uses your former(and no more valid) email when he wrote this.

Actually, I caught that after I hit send.  I resent (just to him), so he
should have it in his inbox.

I've also updated my email alias accordingly.

thx,

Jason.
Mike Turquette Jan. 16, 2013, 1:01 a.m. UTC | #3
Quoting Gregory CLEMENT (2013-01-15 12:46:03)
> On 01/15/2013 07:44 PM, Cong Ding wrote:
> > the variable cpuclk and clk_name should be properly freed when error happens.
> Dear Cong Ding,
> 
> Thanks for you efforts!
> I am happy with this patch and I tested it on the Armada XP DB board, so
> you can now add my:
> 
> Acked-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> 
> Mike,
> 
> could you take this patch for 3.8-rc fixes?
> 
> If you prefer, Jason agrees to take it, but you probably didn't notice it,
> because he uses your former(and no more valid) email when he wrote this.
> 

Acked-by: Mike Turquette <mturquette@linaro.org>

I don't have an existing clk-fixes branch.  This patch is the first fix
I've reviewed for this cycle.  I'm happy if you want to take it and
submit as part of any other mvebu fixes you have.  Otherwise I can take
it.

Let me know what you decide.

Thanks,
Mike

> Thanks,
> 
> Gregory
> 
> > 
> > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > Acked-by: Jason Cooper <jason@lakedaemon.net>
> > ---
> >  drivers/clk/mvebu/clk-cpu.c |    9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c
> > index ff004578..9dd2551 100644
> > --- a/drivers/clk/mvebu/clk-cpu.c
> > +++ b/drivers/clk/mvebu/clk-cpu.c
> > @@ -124,7 +124,7 @@ void __init of_cpu_clk_setup(struct device_node *node)
> >  
> >       clks = kzalloc(ncpus * sizeof(*clks), GFP_KERNEL);
> >       if (WARN_ON(!clks))
> > -             return;
> > +             goto clks_out;
> >  
> >       for_each_node_by_type(dn, "cpu") {
> >               struct clk_init_data init;
> > @@ -134,11 +134,11 @@ void __init of_cpu_clk_setup(struct device_node *node)
> >               int cpu, err;
> >  
> >               if (WARN_ON(!clk_name))
> > -                     return;
> > +                     goto bail_out;
> >  
> >               err = of_property_read_u32(dn, "reg", &cpu);
> >               if (WARN_ON(err))
> > -                     return;
> > +                     goto bail_out;
> >  
> >               sprintf(clk_name, "cpu%d", cpu);
> >               parent_clk = of_clk_get(node, 0);
> > @@ -167,6 +167,9 @@ void __init of_cpu_clk_setup(struct device_node *node)
> >       return;
> >  bail_out:
> >       kfree(clks);
> > +     while(ncpus--)
> > +             kfree(cpuclk[ncpus].clk_name);
> > +clks_out:
> >       kfree(cpuclk);
> >  }
> >  
> > 
> 
> 
> -- 
> Gregory Clement, Free Electrons
> Kernel, drivers, real-time and embedded Linux
> development, consulting, training and support.
> http://free-electrons.com
Jason Cooper Jan. 16, 2013, 2 a.m. UTC | #4
On Tue, Jan 15, 2013 at 05:01:43PM -0800, Mike Turquette wrote:
> Quoting Gregory CLEMENT (2013-01-15 12:46:03)
> > On 01/15/2013 07:44 PM, Cong Ding wrote:
> > > the variable cpuclk and clk_name should be properly freed when error happens.
> > Dear Cong Ding,
> > 
> > Thanks for you efforts!
> > I am happy with this patch and I tested it on the Armada XP DB board, so
> > you can now add my:
> > 
> > Acked-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> > 
> > Mike,
> > 
> > could you take this patch for 3.8-rc fixes?
> > 
> > If you prefer, Jason agrees to take it, but you probably didn't notice it,
> > because he uses your former(and no more valid) email when he wrote this.
> > 
> 
> Acked-by: Mike Turquette <mturquette@linaro.org>
> 
> I don't have an existing clk-fixes branch.  This patch is the first fix
> I've reviewed for this cycle.  I'm happy if you want to take it and
> submit as part of any other mvebu fixes you have.  Otherwise I can take
> it.

I'll take it, no problem.  Thanks for the Ack Mike,

Jason.
Jason Cooper Jan. 23, 2013, 1:08 a.m. UTC | #5
On Tue, Jan 15, 2013 at 07:44:26PM +0100, Cong Ding wrote:
> the variable cpuclk and clk_name should be properly freed when error happens.
> 
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> Acked-by: Jason Cooper <jason@lakedaemon.net>
> ---
>  drivers/clk/mvebu/clk-cpu.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Applied to mvebu/fixes with MikeT's Ack.

thx,

Jason.
diff mbox

Patch

diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c
index ff004578..9dd2551 100644
--- a/drivers/clk/mvebu/clk-cpu.c
+++ b/drivers/clk/mvebu/clk-cpu.c
@@ -124,7 +124,7 @@  void __init of_cpu_clk_setup(struct device_node *node)
 
 	clks = kzalloc(ncpus * sizeof(*clks), GFP_KERNEL);
 	if (WARN_ON(!clks))
-		return;
+		goto clks_out;
 
 	for_each_node_by_type(dn, "cpu") {
 		struct clk_init_data init;
@@ -134,11 +134,11 @@  void __init of_cpu_clk_setup(struct device_node *node)
 		int cpu, err;
 
 		if (WARN_ON(!clk_name))
-			return;
+			goto bail_out;
 
 		err = of_property_read_u32(dn, "reg", &cpu);
 		if (WARN_ON(err))
-			return;
+			goto bail_out;
 
 		sprintf(clk_name, "cpu%d", cpu);
 		parent_clk = of_clk_get(node, 0);
@@ -167,6 +167,9 @@  void __init of_cpu_clk_setup(struct device_node *node)
 	return;
 bail_out:
 	kfree(clks);
+	while(ncpus--)
+		kfree(cpuclk[ncpus].clk_name);
+clks_out:
 	kfree(cpuclk);
 }