public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: baruch@tkos.co.il (Baruch Siach)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] clocksource: timer-digicolor:  Fix resource leaks in error paths.
Date: Wed, 28 Jun 2017 20:58:21 +0300	[thread overview]
Message-ID: <20170628175821.7cbdbicls4an2fdb@tarshish> (raw)
In-Reply-To: <bdf445789302505768066e0c3b56f39dff81e363.1498639341.git.arvind.yadav.cs@gmail.com>

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 -

      reply	other threads:[~2017-06-28 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28  8:45 [PATCH] clocksource: timer-digicolor: Fix resource leaks in error paths Arvind Yadav
2017-06-28 17:58 ` Baruch Siach [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170628175821.7cbdbicls4an2fdb@tarshish \
    --to=baruch@tkos.co.il \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox