From: dinggnu@gmail.com (Cong Ding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] clk: mvebu/clk-cpu.c: fix memory leakage
Date: Tue, 15 Jan 2013 14:41:41 +0000 [thread overview]
Message-ID: <20130115144140.GA1160@gmail.com> (raw)
In-Reply-To: <50F563EC.3030804@free-electrons.com>
On Tue, Jan 15, 2013 at 03:13:00PM +0100, Gregory CLEMENT wrote:
> Dear Cong Ding,
>
> On 01/14/2013 06:18 PM, Cong Ding wrote:
> > the variable cpuclk and clk_name should be properly freed.
> >
>
> Thanks for reporting this memory leak and for your patch but I think
> we could do even better, see below:
>
> > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > ---
> > 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..1a0d84f 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 clk_name_out;
>
> I agree
>
> >
> > err = of_property_read_u32(dn, "reg", &cpu);
> > if (WARN_ON(err))
> > - return;
> > + goto bail_out;
>
> I agree
>
> >
> > sprintf(clk_name, "cpu%d", cpu);
> > parent_clk = of_clk_get(node, 0);
> > @@ -166,7 +166,10 @@ void __init of_cpu_clk_setup(struct device_node *node)
> >
> > return;
> > bail_out:
> > + kfree(clk_name);
>
> Here you free only one clk_name whereas we could have previous clk_name which have
> been already allocated during the for_each_node_by_type loop.
>
> A more annoying thing is that you use clk_name whereas it is only valid in the
> for_each_node_by_type statement and then this patch breaks the compilation:
>
> drivers/clk/mvebu/clk-cpu.c: In function ?of_cpu_clk_setup?:
> drivers/clk/mvebu/clk-cpu.c:169:8: error: ?clk_name? undeclared (first use in this function)
> drivers/clk/mvebu/clk-cpu.c:169:8: note: each undeclared identifier is reported only once for each function it appears in
sorry for the mistake, I am sending version 2.
thanks,
- cong
WARNING: multiple messages have this Message-ID (diff)
From: Cong Ding <dinggnu@gmail.com>
To: Gregory CLEMENT <gregory.clement@free-electrons.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
linux-kernel@vger.kernel.org,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] clk: mvebu/clk-cpu.c: fix memory leakage
Date: Tue, 15 Jan 2013 14:41:41 +0000 [thread overview]
Message-ID: <20130115144140.GA1160@gmail.com> (raw)
In-Reply-To: <50F563EC.3030804@free-electrons.com>
On Tue, Jan 15, 2013 at 03:13:00PM +0100, Gregory CLEMENT wrote:
> Dear Cong Ding,
>
> On 01/14/2013 06:18 PM, Cong Ding wrote:
> > the variable cpuclk and clk_name should be properly freed.
> >
>
> Thanks for reporting this memory leak and for your patch but I think
> we could do even better, see below:
>
> > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > ---
> > 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..1a0d84f 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 clk_name_out;
>
> I agree
>
> >
> > err = of_property_read_u32(dn, "reg", &cpu);
> > if (WARN_ON(err))
> > - return;
> > + goto bail_out;
>
> I agree
>
> >
> > sprintf(clk_name, "cpu%d", cpu);
> > parent_clk = of_clk_get(node, 0);
> > @@ -166,7 +166,10 @@ void __init of_cpu_clk_setup(struct device_node *node)
> >
> > return;
> > bail_out:
> > + kfree(clk_name);
>
> Here you free only one clk_name whereas we could have previous clk_name which have
> been already allocated during the for_each_node_by_type loop.
>
> A more annoying thing is that you use clk_name whereas it is only valid in the
> for_each_node_by_type statement and then this patch breaks the compilation:
>
> drivers/clk/mvebu/clk-cpu.c: In function ‘of_cpu_clk_setup’:
> drivers/clk/mvebu/clk-cpu.c:169:8: error: ‘clk_name’ undeclared (first use in this function)
> drivers/clk/mvebu/clk-cpu.c:169:8: note: each undeclared identifier is reported only once for each function it appears in
sorry for the mistake, I am sending version 2.
thanks,
- cong
next prev parent reply other threads:[~2013-01-15 14:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-14 17:18 [PATCH] clk: mvebu/clk-cpu.c: fix memory leakage Cong Ding
2013-01-15 14:13 ` Gregory CLEMENT
2013-01-15 14:13 ` Gregory CLEMENT
2013-01-15 14:41 ` Cong Ding [this message]
2013-01-15 14:41 ` Cong Ding
2013-01-15 15:23 ` [PATCH v2] " Cong Ding
2013-01-15 15:23 ` Cong Ding
2013-01-15 15:37 ` Jason Cooper
2013-01-15 15:37 ` Jason Cooper
2013-01-15 16:33 ` Gregory CLEMENT
2013-01-15 16:33 ` Gregory CLEMENT
2013-01-15 18:26 ` Cong Ding
2013-01-15 18:26 ` Cong Ding
2013-01-15 18:36 ` Gregory CLEMENT
2013-01-15 18:36 ` Gregory CLEMENT
2013-01-15 18:44 ` [PATCH v3] " Cong Ding
2013-01-15 18:44 ` Cong Ding
2013-01-15 20:46 ` Gregory CLEMENT
2013-01-15 20:46 ` Gregory CLEMENT
2013-01-15 20:57 ` Jason Cooper
2013-01-15 20:57 ` Jason Cooper
2013-01-16 1:01 ` Mike Turquette
2013-01-16 1:01 ` Mike Turquette
2013-01-16 2:00 ` Jason Cooper
2013-01-16 2:00 ` Jason Cooper
2013-01-23 1:08 ` Jason Cooper
2013-01-23 1:08 ` Jason Cooper
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=20130115144140.GA1160@gmail.com \
--to=dinggnu@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.