linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Geert Uytterhoeven <geert+renesas@glider.be>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
	Chris Brandt <Chris.Brandt@renesas.com>,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] clocksource/drivers/renesas-ostm: Fix probe error path
Date: Wed, 7 Aug 2019 20:13:27 +0200	[thread overview]
Message-ID: <db9961d5-e075-5dca-3417-023b7b8ba4c1@linaro.org> (raw)
In-Reply-To: <20190807084635.24173-3-geert+renesas@glider.be>

On 07/08/2019 10:46, Geert Uytterhoeven wrote:
> Fix various issues in the error path of ostm_init():
>   1. Drop error message printing on of_iomap() failure, as the memory
>      allocation core already takes of that,
>   2. Handle irq_of_parse_and_map() failures correctly: it returns
>      unsigned int, hence make irq unsigned int, and zero is an error,
>   3. Propagate/return appropriate error codes instead of -EFAULT.
>   4. Add a missing clk_put(),
>   5. Split the single cleanup block in separate phases, to avoid
>      clk_put() calling WARN() when passed an error pointer.

Does it make sense to convert to timer-of API?

> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v3:
>   - New.
> ---
>  drivers/clocksource/renesas-ostm.c | 54 ++++++++++++++++--------------
>  1 file changed, 29 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/clocksource/renesas-ostm.c b/drivers/clocksource/renesas-ostm.c
> index 37c39b901bb12b38..1e22e54d7b0df40d 100644
> --- a/drivers/clocksource/renesas-ostm.c
> +++ b/drivers/clocksource/renesas-ostm.c
> @@ -155,7 +155,7 @@ static irqreturn_t ostm_timer_interrupt(int irq, void *dev_id)
>  	return IRQ_HANDLED;
>  }
>  
> -static int __init ostm_init_clkevt(struct ostm_device *ostm, int irq,
> +static int __init ostm_init_clkevt(struct ostm_device *ostm, unsigned int irq,
>  			unsigned long rate)
>  {
>  	struct clock_event_device *ced = &ostm->ced;
> @@ -185,11 +185,11 @@ static int __init ostm_init_clkevt(struct ostm_device *ostm, int irq,
>  
>  static int __init ostm_init(struct device_node *np)
>  {
> -	struct ostm_device *ostm;
> -	int ret = -EFAULT;
>  	struct clk *ostm_clk = NULL;
> -	int irq;
> +	struct ostm_device *ostm;
>  	unsigned long rate;
> +	unsigned int irq;
> +	int ret;
>  
>  	ostm = kzalloc(sizeof(*ostm), GFP_KERNEL);
>  	if (!ostm)
> @@ -197,27 +197,29 @@ static int __init ostm_init(struct device_node *np)
>  
>  	ostm->base = of_iomap(np, 0);
>  	if (!ostm->base) {
> -		pr_err("ostm: failed to remap I/O memory\n");
> -		goto err;
> +		ret = -ENOMEM;
> +		goto err_free;
>  	}
>  
>  	irq = irq_of_parse_and_map(np, 0);
> -	if (irq < 0) {
> +	if (!irq) {
>  		pr_err("ostm: Failed to get irq\n");
> -		goto err;
> +		ret = -EINVAL;
> +		goto err_unmap;
>  	}
>  
>  	ostm_clk = of_clk_get(np, 0);
>  	if (IS_ERR(ostm_clk)) {
>  		pr_err("ostm: Failed to get clock\n");
>  		ostm_clk = NULL;
> -		goto err;
> +		ret = PTR_ERR(ostm_clk);
> +		goto err_unmap;
>  	}
>  
>  	ret = clk_prepare_enable(ostm_clk);
>  	if (ret) {
>  		pr_err("ostm: Failed to enable clock\n");
> -		goto err;
> +		goto err_clk_put;
>  	}
>  
>  	rate = clk_get_rate(ostm_clk);
> @@ -229,28 +231,30 @@ static int __init ostm_init(struct device_node *np)
>  	 */
>  	if (!system_clock) {
>  		ret = ostm_init_clksrc(ostm, rate);
> +		if (ret)
> +			goto err_clk_disable;
>  
> -		if (!ret) {
> -			ostm_init_sched_clock(ostm, rate);
> -			pr_info("ostm: used for clocksource\n");
> -		}
> -
> +		ostm_init_sched_clock(ostm, rate);
> +		pr_info("ostm: used for clocksource\n");
>  	} else {
>  		ret = ostm_init_clkevt(ostm, irq, rate);
> +		if (ret)
> +			goto err_clk_disable;
>  
> -		if (!ret)
> -			pr_info("ostm: used for clock events\n");
> -	}
> -
> -err:
> -	if (ret) {
> -		clk_disable_unprepare(ostm_clk);
> -		iounmap(ostm->base);
> -		kfree(ostm);
> -		return ret;
> +		pr_info("ostm: used for clock events\n");
>  	}
>  
>  	return 0;
> +
> +err_clk_disable:
> +	clk_disable_unprepare(ostm_clk);
> +err_clk_put:
> +	clk_put(ostm_clk);
> +err_unmap:
> +	iounmap(ostm->base);
> +err_free:
> +	kfree(ostm);
> +	return ret;
>  }
>  
>  TIMER_OF_DECLARE(ostm, "renesas,ostm", ostm_init);
> 


-- 
 <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


  reply	other threads:[~2019-08-07 18:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07  8:46 [PATCH v3 0/3] clocksource/drivers/ostm: Miscellaneous improvements Geert Uytterhoeven
2019-08-07  8:46 ` [PATCH v3 1/3] clocksource/drivers/renesas-ostm: Use DIV_ROUND_CLOSEST() helper Geert Uytterhoeven
2019-08-16 12:58   ` Simon Horman
2019-08-16 13:00     ` Daniel Lezcano
2019-08-07  8:46 ` [PATCH v3 2/3] clocksource/drivers/renesas-ostm: Fix probe error path Geert Uytterhoeven
2019-08-07 18:13   ` Daniel Lezcano [this message]
2019-08-07 18:56     ` Geert Uytterhoeven
2019-08-16 13:19     ` Simon Horman
2019-08-07  8:46 ` [PATCH v3 3/3] clocksource/drivers/ostm: Use unique device name instead of ostm Geert Uytterhoeven
2019-08-16 13:11   ` Simon Horman
2019-08-16 13:12     ` Simon Horman
2019-08-16 13:18     ` Geert Uytterhoeven
2019-08-21 14:12       ` Simon Horman

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=db9961d5-e075-5dca-3417-023b7b8ba4c1@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=Chris.Brandt@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=jacopo+renesas@jmondi.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).