Skip to contentSkip to conversation

clk: Fix incorrect rate comparison in clk_set_rate()

PATCH Applied Alexander Shiyan 2 participants 2 messages Apr 28, 2025 – Apr 30, 2025 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: Fix incorrect rate comparison in clk_set_rate()

The original condition in clk_set_rate() compared the current clock rate against clk_round_rate(clk, rate). However, when the clock driver doesn't implement .round_rate(), clk_round_rate() falls back to returning the current clock rate via clk_get_rate(). This created a situation where:
clk_get_rate(clk) == clk_round_rate(clk, rate)
would always evaluate to true when .round_rate() is unimplemented.

---
 drivers/clk/clk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/clk.c +2 -1
index bd36878280..8ecfe35094 100644
@@ -169,7 +169,8 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
-	if (clk_get_rate(clk) == clk_round_rate(clk, rate))
+	if (clk_get_rate(clk) ==
+	    (clk->ops->round_rate ? clk_round_rate(clk, rate) : rate))
 		return 0;
 
 	if (!clk->ops->set_rate)
Signature · 1 line
2.39.1
Applied
#1 lore raw
Quoted 8 lines · Alexander Shiyan

The original condition in clk_set_rate() compared the current clock rate against clk_round_rate(clk, rate). However, when the clock driver doesn't implement .round_rate(), clk_round_rate() falls back to returning the current clock rate via clk_get_rate(). This created a situation where:
clk_get_rate(clk) == clk_round_rate(clk, rate)
would always evaluate to true when .round_rate() is unimplemented.

[...]

Applied, thanks!

[1/1] clk: Fix incorrect rate comparison in clk_set_rate()

      https://git.pengutronix.de/cgit/barebox/commit/?id=3111d62b3174 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>