Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751566AbdF1Kjh (ORCPT ); Wed, 28 Jun 2017 06:39:37 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35595 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbdF1Kjb (ORCPT ); Wed, 28 Jun 2017 06:39:31 -0400 From: Arvind Yadav To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org Subject: [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths. Date: Wed, 28 Jun 2017 16:08:42 +0530 Message-Id: X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2150 Lines: 73 Handle return value of clk_prepare_enable. In case of error at init time, rollback iomapping and unprepare clk. Signed-off-by: Arvind Yadav --- 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