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


Groups > linux.kernel > #1676546

[PATCH v2] clocksource: timer-integrator-ap: Fix resource leaks in error paths.

From Arvind Yadav <arvind.yadav.cs@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v2] clocksource: timer-integrator-ap: Fix resource leaks in error paths.
Date 2017-06-28 12:50 +0200
Message-ID <tXiHM-5FO-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Handle return value of clk_prepare_enable. In case of error at init time,
rollback iomapping and unprepare clk.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
Changes in v1:
              Subject was not correct.

 drivers/clocksource/timer-integrator-ap.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/timer-integrator-ap.c b/drivers/clocksource/timer-integrator-ap.c
index 04ad306..27de3f5 100644
--- a/drivers/clocksource/timer-integrator-ap.c
+++ b/drivers/clocksource/timer-integrator-ap.c
@@ -183,6 +183,7 @@ static int __init integrator_ap_timer_init_of(struct device_node *node)
 	unsigned long rate;
 	struct device_node *pri_node;
 	struct device_node *sec_node;
+	struct resource res;
 
 	base = of_io_request_and_map(node, 0, "integrator-timer");
 	if (IS_ERR(base))
@@ -191,9 +192,13 @@ static int __init integrator_ap_timer_init_of(struct device_node *node)
 	clk = of_clk_get(node, 0);
 	if (IS_ERR(clk)) {
 		pr_err("No clock for %s\n", node->name);
-		return PTR_ERR(clk);
+		err = PTR_ERR(clk);
+		goto err_mem;
 	}
-	clk_prepare_enable(clk);
+	err = clk_prepare_enable(clk);
+	if (err)
+		goto err_clk_put;
+
 	rate = clk_get_rate(clk);
 	writel(0, base + TIMER_CTRL);
 
@@ -201,7 +206,7 @@ static int __init integrator_ap_timer_init_of(struct device_node *node)
 				"arm,timer-primary", &path);
 	if (err) {
 		pr_warn("Failed to read property\n");
-		return err;
+		goto err_clk_disable;
 	}
 
 	pri_node = of_find_node_by_path(path);
@@ -210,7 +215,7 @@ static int __init integrator_ap_timer_init_of(struct device_node *node)
 				"arm,timer-secondary", &path);
 	if (err) {
 		pr_warn("Failed to read property\n");
-		return err;
+		goto err_clk_disable;
 	}
 
 
@@ -230,6 +235,16 @@ static int __init integrator_ap_timer_init_of(struct device_node *node)
 	clk_disable_unprepare(clk);
 
 	return 0;
+
+err_clk_disable:
+	clk_disable_unprepare(clk);
+err_clk_put:
+	clk_put(clk);
+err_mem:
+	iounmap(base);
+	of_address_to_resource(node, 0, &res);
+	release_mem_region(res.start, resource_size(&res));
+	return err;
 }
 
 CLOCKSOURCE_OF_DECLARE(integrator_ap_timer, "arm,integrator-timer",
-- 
1.9.1

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH v2] clocksource: timer-integrator-ap:  Fix resource leaks in error paths. Arvind Yadav <arvind.yadav.cs@gmail.com> - 2017-06-28 12:50 +0200

csiph-web