* [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths.
@ 2017-06-28 10:38 Arvind Yadav
0 siblings, 0 replies; 5+ messages in thread
From: Arvind Yadav @ 2017-06-28 10:38 UTC (permalink / raw)
To: daniel.lezcano, tglx; +Cc: linux-kernel
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>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths.
2017-06-28 8:45 ` Arvind Yadav
@ 2017-06-28 17:58 ` Baruch Siach
-1 siblings, 0 replies; 5+ messages in thread
From: Baruch Siach @ 2017-06-28 17:58 UTC (permalink / raw)
To: Arvind Yadav; +Cc: daniel.lezcano, tglx, linux-arm-kernel, linux-kernel
Hi Arvind,
On Wed, Jun 28, 2017 at 02:15:23PM +0530, Arvind Yadav wrote:
> Handle return value of clk_prepare_enable. In case of error at init time,
> rollback iomapping and unprepare clk.
A failure in digicolor_timer_init() means that the system doesn't boot. I'm
not sure how useful the cleanup code would be what that happens.
baruch
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/clocksource/timer-digicolor.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clocksource/timer-digicolor.c b/drivers/clocksource/timer-digicolor.c
> index 94a161e..9360b46 100644
> --- a/drivers/clocksource/timer-digicolor.c
> +++ b/drivers/clocksource/timer-digicolor.c
> @@ -168,15 +168,20 @@ static int __init digicolor_timer_init(struct device_node *node)
> irq = irq_of_parse_and_map(node, dc_timer_dev.timer_id);
> if (irq <= 0) {
> pr_err("Can't parse IRQ\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto err_iounmap;
> }
>
> clk = of_clk_get(node, 0);
> if (IS_ERR(clk)) {
> pr_err("Can't get timer clock\n");
> - return PTR_ERR(clk);
> + ret = PTR_ERR(clk);
> + goto err_iounmap;
> }
> - clk_prepare_enable(clk);
> + ret = clk_prepare_enable(clk);
> + if (ret)
> + goto err_clk_put;
> +
> rate = clk_get_rate(clk);
> dc_timer_dev.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
>
> @@ -193,7 +198,7 @@ static int __init digicolor_timer_init(struct device_node *node)
> &dc_timer_dev.ce);
> if (ret) {
> pr_warn("request of timer irq %d failed (%d)\n", irq, ret);
> - return ret;
> + goto err_unprepare;
> }
>
> dc_timer_dev.ce.cpumask = cpu_possible_mask;
> @@ -202,6 +207,13 @@ static int __init digicolor_timer_init(struct device_node *node)
> clockevents_config_and_register(&dc_timer_dev.ce, rate, 0, 0xffffffff);
>
> return 0;
> +err_unprepare:
> + clk_disable_unprepare(clk);
> +err_clk_put:
> + clk_put(clk);
> +err_iounmap:
> + iounmap(dc_timer_dev.base);
> + return ret;
> }
> CLOCKSOURCE_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer",
> digicolor_timer_init);
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths.
@ 2017-06-28 17:58 ` Baruch Siach
0 siblings, 0 replies; 5+ messages in thread
From: Baruch Siach @ 2017-06-28 17:58 UTC (permalink / raw)
To: linux-arm-kernel
Hi Arvind,
On Wed, Jun 28, 2017 at 02:15:23PM +0530, Arvind Yadav wrote:
> Handle return value of clk_prepare_enable. In case of error at init time,
> rollback iomapping and unprepare clk.
A failure in digicolor_timer_init() means that the system doesn't boot. I'm
not sure how useful the cleanup code would be what that happens.
baruch
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/clocksource/timer-digicolor.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clocksource/timer-digicolor.c b/drivers/clocksource/timer-digicolor.c
> index 94a161e..9360b46 100644
> --- a/drivers/clocksource/timer-digicolor.c
> +++ b/drivers/clocksource/timer-digicolor.c
> @@ -168,15 +168,20 @@ static int __init digicolor_timer_init(struct device_node *node)
> irq = irq_of_parse_and_map(node, dc_timer_dev.timer_id);
> if (irq <= 0) {
> pr_err("Can't parse IRQ\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto err_iounmap;
> }
>
> clk = of_clk_get(node, 0);
> if (IS_ERR(clk)) {
> pr_err("Can't get timer clock\n");
> - return PTR_ERR(clk);
> + ret = PTR_ERR(clk);
> + goto err_iounmap;
> }
> - clk_prepare_enable(clk);
> + ret = clk_prepare_enable(clk);
> + if (ret)
> + goto err_clk_put;
> +
> rate = clk_get_rate(clk);
> dc_timer_dev.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
>
> @@ -193,7 +198,7 @@ static int __init digicolor_timer_init(struct device_node *node)
> &dc_timer_dev.ce);
> if (ret) {
> pr_warn("request of timer irq %d failed (%d)\n", irq, ret);
> - return ret;
> + goto err_unprepare;
> }
>
> dc_timer_dev.ce.cpumask = cpu_possible_mask;
> @@ -202,6 +207,13 @@ static int __init digicolor_timer_init(struct device_node *node)
> clockevents_config_and_register(&dc_timer_dev.ce, rate, 0, 0xffffffff);
>
> return 0;
> +err_unprepare:
> + clk_disable_unprepare(clk);
> +err_clk_put:
> + clk_put(clk);
> +err_iounmap:
> + iounmap(dc_timer_dev.base);
> + return ret;
> }
> CLOCKSOURCE_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer",
> digicolor_timer_init);
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths.
@ 2017-06-28 8:45 ` Arvind Yadav
0 siblings, 0 replies; 5+ messages in thread
From: Arvind Yadav @ 2017-06-28 8:45 UTC (permalink / raw)
To: baruch, daniel.lezcano, tglx; +Cc: linux-arm-kernel, linux-kernel
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>
---
drivers/clocksource/timer-digicolor.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/clocksource/timer-digicolor.c b/drivers/clocksource/timer-digicolor.c
index 94a161e..9360b46 100644
--- a/drivers/clocksource/timer-digicolor.c
+++ b/drivers/clocksource/timer-digicolor.c
@@ -168,15 +168,20 @@ static int __init digicolor_timer_init(struct device_node *node)
irq = irq_of_parse_and_map(node, dc_timer_dev.timer_id);
if (irq <= 0) {
pr_err("Can't parse IRQ\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_iounmap;
}
clk = of_clk_get(node, 0);
if (IS_ERR(clk)) {
pr_err("Can't get timer clock\n");
- return PTR_ERR(clk);
+ ret = PTR_ERR(clk);
+ goto err_iounmap;
}
- clk_prepare_enable(clk);
+ ret = clk_prepare_enable(clk);
+ if (ret)
+ goto err_clk_put;
+
rate = clk_get_rate(clk);
dc_timer_dev.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
@@ -193,7 +198,7 @@ static int __init digicolor_timer_init(struct device_node *node)
&dc_timer_dev.ce);
if (ret) {
pr_warn("request of timer irq %d failed (%d)\n", irq, ret);
- return ret;
+ goto err_unprepare;
}
dc_timer_dev.ce.cpumask = cpu_possible_mask;
@@ -202,6 +207,13 @@ static int __init digicolor_timer_init(struct device_node *node)
clockevents_config_and_register(&dc_timer_dev.ce, rate, 0, 0xffffffff);
return 0;
+err_unprepare:
+ clk_disable_unprepare(clk);
+err_clk_put:
+ clk_put(clk);
+err_iounmap:
+ iounmap(dc_timer_dev.base);
+ return ret;
}
CLOCKSOURCE_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer",
digicolor_timer_init);
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths.
@ 2017-06-28 8:45 ` Arvind Yadav
0 siblings, 0 replies; 5+ messages in thread
From: Arvind Yadav @ 2017-06-28 8:45 UTC (permalink / raw)
To: linux-arm-kernel
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>
---
drivers/clocksource/timer-digicolor.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/clocksource/timer-digicolor.c b/drivers/clocksource/timer-digicolor.c
index 94a161e..9360b46 100644
--- a/drivers/clocksource/timer-digicolor.c
+++ b/drivers/clocksource/timer-digicolor.c
@@ -168,15 +168,20 @@ static int __init digicolor_timer_init(struct device_node *node)
irq = irq_of_parse_and_map(node, dc_timer_dev.timer_id);
if (irq <= 0) {
pr_err("Can't parse IRQ\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_iounmap;
}
clk = of_clk_get(node, 0);
if (IS_ERR(clk)) {
pr_err("Can't get timer clock\n");
- return PTR_ERR(clk);
+ ret = PTR_ERR(clk);
+ goto err_iounmap;
}
- clk_prepare_enable(clk);
+ ret = clk_prepare_enable(clk);
+ if (ret)
+ goto err_clk_put;
+
rate = clk_get_rate(clk);
dc_timer_dev.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
@@ -193,7 +198,7 @@ static int __init digicolor_timer_init(struct device_node *node)
&dc_timer_dev.ce);
if (ret) {
pr_warn("request of timer irq %d failed (%d)\n", irq, ret);
- return ret;
+ goto err_unprepare;
}
dc_timer_dev.ce.cpumask = cpu_possible_mask;
@@ -202,6 +207,13 @@ static int __init digicolor_timer_init(struct device_node *node)
clockevents_config_and_register(&dc_timer_dev.ce, rate, 0, 0xffffffff);
return 0;
+err_unprepare:
+ clk_disable_unprepare(clk);
+err_clk_put:
+ clk_put(clk);
+err_iounmap:
+ iounmap(dc_timer_dev.base);
+ return ret;
}
CLOCKSOURCE_OF_DECLARE(conexant_digicolor, "cnxt,cx92755-timer",
digicolor_timer_init);
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-06-28 17:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-28 10:38 [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths Arvind Yadav
-- strict thread matches above, loose matches on Subject: below --
2017-06-28 8:45 Arvind Yadav
2017-06-28 8:45 ` Arvind Yadav
2017-06-28 17:58 ` Baruch Siach
2017-06-28 17:58 ` Baruch Siach
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.