public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter De Schrijver <pdeschrijver@nvidia.com>
To: ryang <decatf@gmail.com>
Cc: Prashant Gaikwad <pgaikwad@nvidia.com>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	<linux-clk@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero
Date: Mon, 24 Sep 2018 11:06:31 +0300	[thread overview]
Message-ID: <20180924080631.GE7636@tbergstrom-lnx.Nvidia.com> (raw)
In-Reply-To: <20180921220037.16862-1-decatf@gmail.com>

On Fri, Sep 21, 2018 at 06:00:37PM -0400, ryang wrote:
> Calling clk_set_rate or clk_round_rate will lock up the kernel when the
> rate is zero. This avoids the infinite loop and uses a slightly more
> optimized p divider calculation.
> 

Acked-By: Peter De Schrijver <pdeschrijver@nvidia.com>

At some point we should also limit pdiv to its maximum possible value, but
that's not so obvious as we need to take into account PLLs where pdiv is
non-linear.

Peter.

> Signed-off-by: ryang <decatf@gmail.com>
> ---
>  drivers/clk/tegra/clk-pll.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
> index 830d1c87fa7c..17a058c3bbc1 100644
> --- a/drivers/clk/tegra/clk-pll.c
> +++ b/drivers/clk/tegra/clk-pll.c
> @@ -582,9 +582,8 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
>  	}
>  
>  	/* Raise VCO to guarantee 0.5% accuracy */
> -	for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq;
> -	     cfg->output_rate <<= 1)
> -		p_div++;
> +	p_div = rate ? fls((200 * cfreq) / rate) : 0;
> +	cfg->output_rate = rate << p_div;
>  
>  	cfg->m = parent_rate / cfreq;
>  	cfg->n = cfg->output_rate / cfreq;
> -- 
> 2.17.1
> 

  parent reply	other threads:[~2018-09-24  8:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21 22:00 [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero ryang
2018-09-21 22:00 ` ryang
2018-09-24  8:06 ` Peter De Schrijver [this message]
2018-09-24  8:06   ` Peter De Schrijver
2018-09-24 11:40 ` Thierry Reding
2018-09-24 11:40   ` Thierry Reding
2018-10-01 22:08 ` Stephen Boyd
2018-10-02  7:35   ` Stephen Boyd

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=20180924080631.GE7636@tbergstrom-lnx.Nvidia.com \
    --to=pdeschrijver@nvidia.com \
    --cc=decatf@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=pgaikwad@nvidia.com \
    --cc=sboyd@kernel.org \
    --cc=thierry.reding@gmail.com \
    /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