Commit 8b5bf64c authored by Feng Mingxi's avatar Feng Mingxi Committed by Daniel Lezcano

clocksource/drivers/cadence-ttc: Fix memory leak in ttc_timer_probe

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: e932900a ("arm: zynq: Use standard timer binding")
Fixes: 70504f31 ("clocksource/drivers/cadence_ttc: Convert init function to return error")
Signed-off-by: default avatarFeng Mingxi <m202271825@hust.edu.cn>
Reviewed-by: default avatarDongliang Mu <dzm91@hust.edu.cn>
Acked-by: default avatarMichal Simek <michal.simek@amd.com>
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230425065611.702917-1-m202271825@hust.edu.cn
parent 6d0d4df8
...@@ -486,10 +486,10 @@ static int __init ttc_timer_probe(struct platform_device *pdev) ...@@ -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 * 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) * 2nd TTC hence the irq_of_parse_and_map(,1)
*/ */
timer_baseaddr = of_iomap(timer, 0); timer_baseaddr = devm_of_iomap(&pdev->dev, timer, 0, NULL);
if (!timer_baseaddr) { if (IS_ERR(timer_baseaddr)) {
pr_err("ERROR: invalid timer base address\n"); pr_err("ERROR: invalid timer base address\n");
return -ENXIO; return PTR_ERR(timer_baseaddr);
} }
irq = irq_of_parse_and_map(timer, 1); irq = irq_of_parse_and_map(timer, 1);
...@@ -513,20 +513,27 @@ static int __init ttc_timer_probe(struct platform_device *pdev) ...@@ -513,20 +513,27 @@ static int __init ttc_timer_probe(struct platform_device *pdev)
clk_ce = of_clk_get(timer, clksel); clk_ce = of_clk_get(timer, clksel);
if (IS_ERR(clk_ce)) { if (IS_ERR(clk_ce)) {
pr_err("ERROR: timer input clock not found\n"); 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); ret = ttc_setup_clocksource(clk_cs, timer_baseaddr, timer_width);
if (ret) if (ret)
return ret; goto put_clk_ce;
ret = ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq); ret = ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
if (ret) if (ret)
return ret; goto put_clk_ce;
pr_info("%pOFn #0 at %p, irq=%d\n", timer, timer_baseaddr, irq); pr_info("%pOFn #0 at %p, irq=%d\n", timer, timer_baseaddr, irq);
return 0; 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[] = { static const struct of_device_id ttc_timer_of_match[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment