mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@amd.com>
To: "Feng Mingxi" <m202271825@hust.edu.cn>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Daniel Lezcano" <daniel.lezcano@linaro.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Sören Brinkmann" <soren.brinkmann@xilinx.com>
Cc: hust-os-kernel-patches@googlegroups.com,
	Dongliang Mu <dzm91@hust.edu.cn>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] clocksource: cadence-ttc: fix memory leak in ttc_timer_probe
Date: Wed, 26 Apr 2023 16:49:25 +0200	[thread overview]
Message-ID: <d1e995fc-02f1-9995-6910-5bc6254e70bb@amd.com> (raw)
In-Reply-To: <20230425065611.702917-1-m202271825@hust.edu.cn>



On 4/25/23 08:56, Feng Mingxi wrote:
> 
> Smatch reports:
> drivers/clocksource/timer-cadence-ttc.c:529 ttc_timer_probe()
> warn: 'timer_baseaddr' from of_iomap() not released on lines: 498,508,516.
> 
> timer_baseaddr may have the problem of not being released after use,
> I replaced it with the devm_of_iomap() function and added the clk_put()
> function to cleanup the "clk_ce" and "clk_cs".
> 
> Fixes: e932900a3279 ("arm: zynq: Use standard timer binding")
> Fixes: 70504f311d4b ("clocksource/drivers/cadence_ttc: Convert init function to return error")
> Signed-off-by: Feng Mingxi <m202271825@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
> ---
> The issue is discovered by static analysis, and the patch is not tested yet.
> ---
>   drivers/clocksource/timer-cadence-ttc.c | 19 +++++++++++++------
>   1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-cadence-ttc.c b/drivers/clocksource/timer-cadence-ttc.c
> index 4efd0cf3b602..0d52e28fea4d 100644
> --- a/drivers/clocksource/timer-cadence-ttc.c
> +++ b/drivers/clocksource/timer-cadence-ttc.c
> @@ -486,10 +486,10 @@ static int __init ttc_timer_probe(struct platform_device *pdev)
>           * and use it. Note that the event timer uses the interrupt and it's the
>           * 2nd TTC hence the irq_of_parse_and_map(,1)
>           */
> -       timer_baseaddr = of_iomap(timer, 0);
> -       if (!timer_baseaddr) {
> +       timer_baseaddr = devm_of_iomap(&pdev->dev, timer, 0, NULL);
> +       if (IS_ERR(timer_baseaddr)) {
>                  pr_err("ERROR: invalid timer base address\n");
> -               return -ENXIO;
> +               return PTR_ERR(timer_baseaddr);
>          }
> 
>          irq = irq_of_parse_and_map(timer, 1);
> @@ -513,20 +513,27 @@ static int __init ttc_timer_probe(struct platform_device *pdev)
>          clk_ce = of_clk_get(timer, clksel);
>          if (IS_ERR(clk_ce)) {
>                  pr_err("ERROR: timer input clock not found\n");
> -               return PTR_ERR(clk_ce);
> +               ret = PTR_ERR(clk_ce);
> +               goto put_clk_cs;
>          }
> 
>          ret = ttc_setup_clocksource(clk_cs, timer_baseaddr, timer_width);
>          if (ret)
> -               return ret;
> +               goto put_clk_ce;
> 
>          ret = ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
>          if (ret)
> -               return ret;
> +               goto put_clk_ce;
> 
>          pr_info("%pOFn #0 at %p, irq=%d\n", timer, timer_baseaddr, irq);
> 
>          return 0;
> +
> +put_clk_ce:
> +       clk_put(clk_ce);
> +put_clk_cs:
> +       clk_put(clk_cs);
> +       return ret;
>   }
> 
>   static const struct of_device_id ttc_timer_of_match[] = {
> --
> 2.34.1
> 

Acked-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal

  reply	other threads:[~2023-04-26 14:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25  6:56 Feng Mingxi
2023-04-26 14:49 ` Michal Simek [this message]
2023-06-26  9:11 ` [tip: timers/core] clocksource/drivers/cadence-ttc: Fix " tip-bot2 for Feng Mingxi

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=d1e995fc-02f1-9995-6910-5bc6254e70bb@amd.com \
    --to=michal.simek@amd.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=dzm91@hust.edu.cn \
    --cc=hust-os-kernel-patches@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m202271825@hust.edu.cn \
    --cc=michal.simek@xilinx.com \
    --cc=soren.brinkmann@xilinx.com \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®