Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1441265 > unrolled thread

[PATCH -next] clocksource: cadence_ttc: Fix error handling in ttc_setup_clockevent()

Started byweiyj_lk@163.com
First post2016-07-12 13:30 +0200
Last post2016-07-12 13:30 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH -next] clocksource: cadence_ttc: Fix error handling in ttc_setup_clockevent() weiyj_lk@163.com - 2016-07-12 13:30 +0200

#1441265 — [PATCH -next] clocksource: cadence_ttc: Fix error handling in ttc_setup_clockevent()

Fromweiyj_lk@163.com
Date2016-07-12 13:30 +0200
Subject[PATCH -next] clocksource: cadence_ttc: Fix error handling in ttc_setup_clockevent()
Message-ID<rU42Z-4c1-3@gated-at.bofh.it>
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;
 }
 
 /**

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web