clocksource/drivers/moxart: fix memory leak on timer on error exit paths
PATCH 1/1 clocksource/drivers/moxart: fix memory leak on timer on error exit paths
From: Colin Ian King <[email protected]>
The timer is not being free'd on the error exit paths, causing a small memory leak. Add an err exit path that free's timer and returns the error status in ret.
Signed-off-by Colin Ian King <[email protected]>
--- drivers/clocksource/moxart_timer.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/clocksource/moxart_timer.c +13 -6
@@ -161,19 +161,22 @@ static int __init moxart_timer_init(struct device_node *node) timer->base =of_iomap (node,0 );if (!timer->base) {pr_err ("%s: of_iomap failed\n" , node->full_name); -return -ENXIO ; + ret = -ENXIO ; + goto err; } irq =irq_of_parse_and_map (node,0 );if (irq <=0 ) {pr_err ("%s: irq_of_parse_and_map failed\n" , node->full_name); -return -EINVAL ; + ret = -EINVAL ; + goto err; } clk =of_clk_get (node,0 );if (IS_ERR (clk)) {pr_err ("%s: of_clk_get failed\n" , node->full_name); -return PTR_ERR (clk); + ret =PTR_ERR (clk); + goto err; } pclk =clk_get_rate (clk);
@@ -186,7 +189,8 @@ static int __init moxart_timer_init(struct device_node *node) timer->t1_disable_val =ASPEED_TIMER1_DISABLE ; }else {pr_err ("%s: unknown platform\n" , node->full_name); -return -EINVAL ; + ret = -EINVAL ; + goto err; } timer->count_per_tick =DIV_ROUND_CLOSEST (pclk,HZ );
@@ -208,14 +212,14 @@ static int __init moxart_timer_init(struct device_node *node) clocksource_mmio_readl_down);if (ret) {pr_err ("%s: clocksource_mmio_init failed\n" , node->full_name); -return ret; + goto err; } ret =request_irq (irq, moxart_timer_interrupt,IRQF_TIMER , node->name, &timer->clkevt);if (ret) {pr_err ("%s: setup_irq failed\n" , node->full_name); -return ret; + goto err; }/* Clear match registers */
@@ -241,6 +245,9 @@ static int __init moxart_timer_init(struct device_node *node)clockevents_config_and_register (&timer->clkevt, pclk,0x4 ,0xfffffffe );return 0 ; +err: +kfree (timer); +return ret; }CLOCKSOURCE_OF_DECLARE (moxart,"moxa,moxart-timer" , moxart_timer_init);CLOCKSOURCE_OF_DECLARE (aspeed,"aspeed,ast2400-timer" , moxart_timer_init);
Signature · 1 line
2.10.2
Quoted 5 lines · Colin King
From: Colin Ian King <[email protected]>
The timer is not being free'd on the error exit paths, causing a small memory leak. Add an err exit path that free's timer and returns the error status in ret.
Hi Colin,
thanks for sending a fix for this. However, if you are in the process of fixing the error handling in this init function, you should take the opportunity to fix not only the mem leak but also rollback clk_get and request_irq.
-- Daniel
[ ... ]
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog