All of lore.kernel.org
 help / color / mirror / Atom feed
From: <wang.yi59@zte.com.cn>
To: <sboyd@kernel.org>
Cc: <paul.burton@mips.com>, <mturquette@baylibre.com>,
	<linux-mips@linux-mips.org>, <linux-clk@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <zhong.weidong@zte.com.cn>,
	<up2wing@163.com>
Subject: Re: Re: [PATCH v2] clk: boston: fix possible memory leak in clk_boston_setup()
Date: Tue, 30 Oct 2018 14:13:24 +0800 (CST)	[thread overview]
Message-ID: <201810301413240217200@zte.com.cn> (raw)
In-Reply-To: <154083382731.98144.10932242759017894372@swboyd.mtv.corp.google.com>


[-- Attachment #1.1: Type: text/plain, Size: 2510 bytes --]

> Quoting Yi Wang (2018-10-29 01:31:47)
> > 'onecell' is malloced in clk_boston_setup(), but is not freed
> > before leaving from the error handling cases.
>
> How did you find this? Visual inspection? Some coccinelle script?

Smatch report this:
drivers/clk/imgtec/clk-boston.c:76 clk_boston_setup() warn: possible memory leak of 'onecell'
drivers/clk/imgtec/clk-boston.c:83 clk_boston_setup() warn: possible memory leak of 'onecell'
drivers/clk/imgtec/clk-boston.c:90 clk_boston_setup() warn: possible memory leak of 'onecell'

>
> >
> > Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> > ---
> > v2: fix syntax issue in comment, thanks to  Sergei.
> >
> >  drivers/clk/imgtec/clk-boston.c | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c
> > index 15af423..f5d54a6 100644
> > --- a/drivers/clk/imgtec/clk-boston.c
> > +++ b/drivers/clk/imgtec/clk-boston.c
> > @@ -73,27 +73,32 @@ static void __init clk_boston_setup(struct device_node *np)
> >         hw = clk_hw_register_fixed_rate(NULL, "input", NULL, 0, in_freq);
> >         if (IS_ERR(hw)) {
> >                 pr_err("failed to register input clock: %ld\n", PTR_ERR(hw));
> > -               return;
> > +               goto error;
> >         }
> >         onecell->hws[BOSTON_CLK_INPUT] = hw;
> >
> >         hw = clk_hw_register_fixed_rate(NULL, "sys", "input", 0, sys_freq);
> >         if (IS_ERR(hw)) {
> >                 pr_err("failed to register sys clock: %ld\n", PTR_ERR(hw));
> > -               return;
> > +               goto error;
> >         }
> >         onecell->hws[BOSTON_CLK_SYS] = hw;
> >
> >         hw = clk_hw_register_fixed_rate(NULL, "cpu", "input", 0, cpu_freq);
> >         if (IS_ERR(hw)) {
> >                 pr_err("failed to register cpu clock: %ld\n", PTR_ERR(hw));
> > -               return;
> > +               goto error;
> >         }
> >         onecell->hws[BOSTON_CLK_CPU] = hw;
> >
> >         err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, onecell);
> >         if (err)
> >                 pr_err("failed to add DT provider: %d\n", err);
> > +
> > +       return;
> > +
> > +error:
> > +       kfree(onecell);
>
> Ok, sure. But then clks are still left registered on failure?

Yeah, but this patch does not change the original flow of the function, so I suppose
if you deem this is not proper, it's better to improve that in another patch, what do
you think?


---
Best wishes
Yi Wang

WARNING: multiple messages have this Message-ID (diff)
From: <wang.yi59@zte.com.cn>
To: sboyd@kernel.org
Cc: paul.burton@mips.com, mturquette@baylibre.com,
	linux-mips@linux-mips.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn,
	up2wing@163.com
Subject: Re: Re: [PATCH v2] clk: boston: fix possible memory leak in clk_boston_setup()
Date: Tue, 30 Oct 2018 14:13:24 +0800 (CST)	[thread overview]
Message-ID: <201810301413240217200@zte.com.cn> (raw)
Message-ID: <20181030061324.rE9TIlmIQpjSD5S2bmLo1L8P1nlTcI4AqnBLaaY-ly8@z> (raw)
In-Reply-To: <154083382731.98144.10932242759017894372@swboyd.mtv.corp.google.com>


[-- Attachment #1.1: Type: text/plain, Size: 2510 bytes --]

> Quoting Yi Wang (2018-10-29 01:31:47)
> > 'onecell' is malloced in clk_boston_setup(), but is not freed
> > before leaving from the error handling cases.
>
> How did you find this? Visual inspection? Some coccinelle script?

Smatch report this:
drivers/clk/imgtec/clk-boston.c:76 clk_boston_setup() warn: possible memory leak of 'onecell'
drivers/clk/imgtec/clk-boston.c:83 clk_boston_setup() warn: possible memory leak of 'onecell'
drivers/clk/imgtec/clk-boston.c:90 clk_boston_setup() warn: possible memory leak of 'onecell'

>
> >
> > Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> > ---
> > v2: fix syntax issue in comment, thanks to  Sergei.
> >
> >  drivers/clk/imgtec/clk-boston.c | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c
> > index 15af423..f5d54a6 100644
> > --- a/drivers/clk/imgtec/clk-boston.c
> > +++ b/drivers/clk/imgtec/clk-boston.c
> > @@ -73,27 +73,32 @@ static void __init clk_boston_setup(struct device_node *np)
> >         hw = clk_hw_register_fixed_rate(NULL, "input", NULL, 0, in_freq);
> >         if (IS_ERR(hw)) {
> >                 pr_err("failed to register input clock: %ld\n", PTR_ERR(hw));
> > -               return;
> > +               goto error;
> >         }
> >         onecell->hws[BOSTON_CLK_INPUT] = hw;
> >
> >         hw = clk_hw_register_fixed_rate(NULL, "sys", "input", 0, sys_freq);
> >         if (IS_ERR(hw)) {
> >                 pr_err("failed to register sys clock: %ld\n", PTR_ERR(hw));
> > -               return;
> > +               goto error;
> >         }
> >         onecell->hws[BOSTON_CLK_SYS] = hw;
> >
> >         hw = clk_hw_register_fixed_rate(NULL, "cpu", "input", 0, cpu_freq);
> >         if (IS_ERR(hw)) {
> >                 pr_err("failed to register cpu clock: %ld\n", PTR_ERR(hw));
> > -               return;
> > +               goto error;
> >         }
> >         onecell->hws[BOSTON_CLK_CPU] = hw;
> >
> >         err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, onecell);
> >         if (err)
> >                 pr_err("failed to add DT provider: %d\n", err);
> > +
> > +       return;
> > +
> > +error:
> > +       kfree(onecell);
>
> Ok, sure. But then clks are still left registered on failure?

Yeah, but this patch does not change the original flow of the function, so I suppose
if you deem this is not proper, it's better to improve that in another patch, what do
you think?


---
Best wishes
Yi Wang

  reply	other threads:[~2018-10-30  6:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29  8:31 [PATCH v2] clk: boston: fix possible memory leak in clk_boston_setup() Yi Wang
2018-10-29 17:23 ` Stephen Boyd
2018-10-29 17:23   ` Stephen Boyd
2018-10-30  6:13   ` wang.yi59 [this message]
2018-10-30  6:13     ` wang.yi59
2018-10-30 16:25     ` Stephen Boyd
2018-10-31  2:42       ` wang.yi59
2018-10-31  2:42         ` wang.yi59
2018-10-31  3:05       ` wang.yi59
2018-10-31  3:05         ` wang.yi59
2018-10-31  3:30       ` wang.yi59
2018-10-31  3:30         ` wang.yi59
2018-10-31  3:44       ` wang.yi59
2018-10-31  3:44         ` wang.yi59
2018-10-31  6:59       ` wang.yi59
2018-10-31  6:59         ` wang.yi59

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=201810301413240217200@zte.com.cn \
    --to=wang.yi59@zte.com.cn \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=mturquette@baylibre.com \
    --cc=paul.burton@mips.com \
    --cc=sboyd@kernel.org \
    --cc=up2wing@163.com \
    --cc=zhong.weidong@zte.com.cn \
    /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.