linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero
@ 2018-09-21 22:00 ryang
  2018-09-24  8:06 ` Peter De Schrijver
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: ryang @ 2018-09-21 22:00 UTC (permalink / raw)
  To: Peter De Schrijver
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel, ryang

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.

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero
  2018-09-21 22:00 [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero ryang
@ 2018-09-24  8:06 ` Peter De Schrijver
  2018-09-24 11:40 ` Thierry Reding
  2018-10-01 22:08 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Peter De Schrijver @ 2018-09-24  8:06 UTC (permalink / raw)
  To: ryang
  Cc: Prashant Gaikwad, Michael Turquette, Stephen Boyd,
	Thierry Reding, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero
  2018-09-21 22:00 [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero ryang
  2018-09-24  8:06 ` Peter De Schrijver
@ 2018-09-24 11:40 ` Thierry Reding
  2018-10-01 22:08 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2018-09-24 11:40 UTC (permalink / raw)
  To: ryang
  Cc: Peter De Schrijver, Prashant Gaikwad, Michael Turquette,
	Stephen Boyd, Jonathan Hunter, linux-clk, linux-tegra,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 436 bytes --]

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.
> 
> Signed-off-by: ryang <decatf@gmail.com>
> ---
>  drivers/clk/tegra/clk-pll.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero
  2018-09-21 22:00 [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero ryang
  2018-09-24  8:06 ` Peter De Schrijver
  2018-09-24 11:40 ` Thierry Reding
@ 2018-10-01 22:08 ` Stephen Boyd
  2018-10-02  7:35   ` Stephen Boyd
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Boyd @ 2018-10-01 22:08 UTC (permalink / raw)
  To: Peter De Schrijver, ryang
  Cc: Prashant Gaikwad, Michael Turquette, Thierry Reding,
	Jonathan Hunter, linux-clk, linux-tegra, linux-kernel, ryang

Quoting ryang (2018-09-21 15:00:37)
> 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.
> 
> Signed-off-by: ryang <decatf@gmail.com>

Do you have a more proper name? Or you want the author name to show up as
"ryang"?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero
  2018-10-01 22:08 ` Stephen Boyd
@ 2018-10-02  7:35   ` Stephen Boyd
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2018-10-02  7:35 UTC (permalink / raw)
  To: Peter De Schrijver, ryang
  Cc: Prashant Gaikwad, Michael Turquette, Thierry Reding,
	Jonathan Hunter, linux-clk, linux-tegra, linux-kernel, ryang

Quoting Stephen Boyd (2018-10-01 15:08:46)
> Quoting ryang (2018-09-21 15:00:37)
> > 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.
> > 
> > Signed-off-by: ryang <decatf@gmail.com>
> 
> Do you have a more proper name? Or you want the author name to show up as
> "ryang"?
> 

I see a v2 on the list, and it looks similar so I'm going to assume this
is superseded now.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-10-02  7:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-21 22:00 [PATCH] clk: tegra: Fix an infinite loop when clock rate is zero ryang
2018-09-24  8:06 ` Peter De Schrijver
2018-09-24 11:40 ` Thierry Reding
2018-10-01 22:08 ` Stephen Boyd
2018-10-02  7:35   ` Stephen Boyd

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