Skip to content

Commit 8b5bf64

Browse files
fmx-hustdlezcano
authored andcommitted
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: e932900 ("arm: zynq: Use standard timer binding") Fixes: 70504f3 ("clocksource/drivers/cadence_ttc: Convert init function to return error") Signed-off-by: Feng Mingxi <[email protected]> Reviewed-by: Dongliang Mu <[email protected]> Acked-by: Michal Simek <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6d0d4df commit 8b5bf64

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/clocksource/timer-cadence-ttc.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ static int __init ttc_timer_probe(struct platform_device *pdev)
486486
* and use it. Note that the event timer uses the interrupt and it's the
487487
* 2nd TTC hence the irq_of_parse_and_map(,1)
488488
*/
489-
timer_baseaddr = of_iomap(timer, 0);
490-
if (!timer_baseaddr) {
489+
timer_baseaddr = devm_of_iomap(&pdev->dev, timer, 0, NULL);
490+
if (IS_ERR(timer_baseaddr)) {
491491
pr_err("ERROR: invalid timer base address\n");
492-
return -ENXIO;
492+
return PTR_ERR(timer_baseaddr);
493493
}
494494

495495
irq = irq_of_parse_and_map(timer, 1);
@@ -513,20 +513,27 @@ static int __init ttc_timer_probe(struct platform_device *pdev)
513513
clk_ce = of_clk_get(timer, clksel);
514514
if (IS_ERR(clk_ce)) {
515515
pr_err("ERROR: timer input clock not found\n");
516-
return PTR_ERR(clk_ce);
516+
ret = PTR_ERR(clk_ce);
517+
goto put_clk_cs;
517518
}
518519

519520
ret = ttc_setup_clocksource(clk_cs, timer_baseaddr, timer_width);
520521
if (ret)
521-
return ret;
522+
goto put_clk_ce;
522523

523524
ret = ttc_setup_clockevent(clk_ce, timer_baseaddr + 4, irq);
524525
if (ret)
525-
return ret;
526+
goto put_clk_ce;
526527

527528
pr_info("%pOFn #0 at %p, irq=%d\n", timer, timer_baseaddr, irq);
528529

529530
return 0;
531+
532+
put_clk_ce:
533+
clk_put(clk_ce);
534+
put_clk_cs:
535+
clk_put(clk_cs);
536+
return ret;
530537
}
531538

532539
static const struct of_device_id ttc_timer_of_match[] = {

0 commit comments

Comments
 (0)