Commit fb735563 authored by Qinrun Dai's avatar Qinrun Dai Committed by Daniel Lezcano

clocksource/drivers/davinci: Fix memory leak in davinci_timer_register when init fails

Smatch reports:
drivers/clocksource/timer-davinci.c:332 davinci_timer_register()
warn: 'base' from ioremap() not released on lines: 274.

Fix this and other potential memory leak problems
by adding a set of corresponding exit lables.

Fixes: 721154f9 ("clocksource/drivers/davinci: Add support for clockevents")
Signed-off-by: default avatarQinrun Dai <flno@hust.edu.cn>
Link: https://lore.kernel.org/r/20230413135037.1505799-1-flno@hust.edu.cnSigned-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent b6f228e8
...@@ -257,21 +257,25 @@ int __init davinci_timer_register(struct clk *clk, ...@@ -257,21 +257,25 @@ int __init davinci_timer_register(struct clk *clk,
resource_size(&timer_cfg->reg), resource_size(&timer_cfg->reg),
"davinci-timer")) { "davinci-timer")) {
pr_err("Unable to request memory region\n"); pr_err("Unable to request memory region\n");
return -EBUSY; rv = -EBUSY;
goto exit_clk_disable;
} }
base = ioremap(timer_cfg->reg.start, resource_size(&timer_cfg->reg)); base = ioremap(timer_cfg->reg.start, resource_size(&timer_cfg->reg));
if (!base) { if (!base) {
pr_err("Unable to map the register range\n"); pr_err("Unable to map the register range\n");
return -ENOMEM; rv = -ENOMEM;
goto exit_mem_region;
} }
davinci_timer_init(base); davinci_timer_init(base);
tick_rate = clk_get_rate(clk); tick_rate = clk_get_rate(clk);
clockevent = kzalloc(sizeof(*clockevent), GFP_KERNEL); clockevent = kzalloc(sizeof(*clockevent), GFP_KERNEL);
if (!clockevent) if (!clockevent) {
return -ENOMEM; rv = -ENOMEM;
goto exit_iounmap_base;
}
clockevent->dev.name = "tim12"; clockevent->dev.name = "tim12";
clockevent->dev.features = CLOCK_EVT_FEAT_ONESHOT; clockevent->dev.features = CLOCK_EVT_FEAT_ONESHOT;
...@@ -296,7 +300,7 @@ int __init davinci_timer_register(struct clk *clk, ...@@ -296,7 +300,7 @@ int __init davinci_timer_register(struct clk *clk,
"clockevent/tim12", clockevent); "clockevent/tim12", clockevent);
if (rv) { if (rv) {
pr_err("Unable to request the clockevent interrupt\n"); pr_err("Unable to request the clockevent interrupt\n");
return rv; goto exit_free_clockevent;
} }
davinci_clocksource.dev.rating = 300; davinci_clocksource.dev.rating = 300;
...@@ -323,13 +327,27 @@ int __init davinci_timer_register(struct clk *clk, ...@@ -323,13 +327,27 @@ int __init davinci_timer_register(struct clk *clk,
rv = clocksource_register_hz(&davinci_clocksource.dev, tick_rate); rv = clocksource_register_hz(&davinci_clocksource.dev, tick_rate);
if (rv) { if (rv) {
pr_err("Unable to register clocksource\n"); pr_err("Unable to register clocksource\n");
return rv; goto exit_free_irq;
} }
sched_clock_register(davinci_timer_read_sched_clock, sched_clock_register(davinci_timer_read_sched_clock,
DAVINCI_TIMER_CLKSRC_BITS, tick_rate); DAVINCI_TIMER_CLKSRC_BITS, tick_rate);
return 0; return 0;
exit_free_irq:
free_irq(timer_cfg->irq[DAVINCI_TIMER_CLOCKEVENT_IRQ].start,
clockevent);
exit_free_clockevent:
kfree(clockevent);
exit_iounmap_base:
iounmap(base);
exit_mem_region:
release_mem_region(timer_cfg->reg.start,
resource_size(&timer_cfg->reg));
exit_clk_disable:
clk_disable_unprepare(clk);
return rv;
} }
static int __init of_davinci_timer_register(struct device_node *np) static int __init of_davinci_timer_register(struct device_node *np)
......
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