Skip to contentSkip to conversation

clk: tegra: Fix an infinite loop when clock rate is zero

PATCH In review ryang 4 participants 5 messages Sep 21, 2018 – Oct 2, 2018

Subsystems (3)
lore
Share & tools
lore

ryang

author
#0 lore raw

PATCH 1/1 clk: tegra: Fix an infinite loop when clock rate is zero

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.

---
 drivers/clk/tegra/clk-pll.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-pll.c +2 -3
index 830d1c87fa7c..17a058c3bbc1 100644
@@ -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;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · 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.

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.

Quoted 24 lines
---
 drivers/clk/tegra/clk-pll.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-pll.c +2 -3
index 830d1c87fa7c..17a058c3bbc1 100644
@@ -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;
Signature · 1 line
2.17.1
maintainer
#3 lore raw
In reply to ryang

Quoting ryang (2018-09-21 15:00:37)

Quoted 5 lines

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.

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

maintainer
#4 lore raw

Quoting Stephen Boyd (2018-10-01 15:08:46)

Quoted 10 lines

Quoting ryang (2018-09-21 15:00:37)

Quoted 5 lines

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.

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.