* [PATCH -next] clocksource: cadence_ttc: Fix error handling in ttc_setup_clockevent()
@ 2016-07-12 11:20 weiyj_lk
0 siblings, 0 replies; only message in thread
From: weiyj_lk @ 2016-07-12 11:20 UTC (permalink / raw)
To: michal.simek, soren.brinkmann, daniel.lezcano, tglx
Cc: Wei Yongjun, linux-arm-kernel, linux-kernel
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
resources alloc in this function should be release in the error
handling, otherwise it will cause resource leak.
Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
drivers/clocksource/cadence_ttc_timer.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c
index fbfbdec..020b85c 100644
--- a/drivers/clocksource/cadence_ttc_timer.c
+++ b/drivers/clocksource/cadence_ttc_timer.c
@@ -418,10 +418,8 @@ static int __init ttc_setup_clockevent(struct clk *clk,
ttcce->ttc.clk = clk;
err = clk_prepare_enable(ttcce->ttc.clk);
- if (err) {
- kfree(ttcce);
- return err;
- }
+ if (err)
+ goto err_clk;
ttcce->ttc.clk_rate_change_nb.notifier_call =
ttc_rate_change_clockevent_cb;
@@ -431,7 +429,7 @@ static int __init ttc_setup_clockevent(struct clk *clk,
&ttcce->ttc.clk_rate_change_nb);
if (err) {
pr_warn("Unable to register clock notifier.\n");
- return err;
+ goto err_reg;
}
ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk);
@@ -460,15 +458,21 @@ static int __init ttc_setup_clockevent(struct clk *clk,
err = request_irq(irq, ttc_clock_event_interrupt,
IRQF_TIMER, ttcce->ce.name, ttcce);
- if (err) {
- kfree(ttcce);
- return err;
- }
+ if (err)
+ goto err_irq;
clockevents_config_and_register(&ttcce->ce,
ttcce->ttc.freq / PRESCALE, 1, 0xfffe);
return 0;
+err_irq:
+ clk_notifier_unregister(ttcce->ttc.clk,
+ &ttcce->ttc.clk_rate_change_nb);
+err_reg:
+ clk_disable_unprepare(ttcce->ttc.clk);
+err_clk:
+ kfree(ttcce);
+ return err;
}
/**
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-07-12 11:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12 11:20 [PATCH -next] clocksource: cadence_ttc: Fix error handling in ttc_setup_clockevent() weiyj_lk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).