[PATCH 4/8] clk: fixed-factor: use 64-bit arithmetic in recalc_rate

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Aug 31 12:35:51 PDT 2026


From: Ahmad Fatoum <a.fatoum at barebox.org>

(parent_rate / div) * mult loses precision in the intermediate division
and parent_rate * mult can exceed 32 bits. Use u64 multiplication and
do_div like Linux' clk_factor_recalc_rate() does since commit
bab53301c38 ("clk: fixed-factor: round_rate should use do_div").

Fixes: f2e2e596a221 ("clk: initial common clk support")
Reported-by: Claude:opus-4.6
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/clk/clk-fixed-factor.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index d2c808d40c63..a163c3de28b6 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -9,13 +9,17 @@
 #include <malloc.h>
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <linux/math64.h>
 
 static unsigned long clk_fixed_factor_recalc_rate(struct clk_hw *hw,
 		unsigned long parent_rate)
 {
 	struct clk_fixed_factor *f = to_clk_fixed_factor(hw);
+	unsigned long long int rate;
 
-	return (parent_rate / f->div) * f->mult;
+	rate = (unsigned long long int)parent_rate * f->mult;
+	do_div(rate, f->div);
+	return (unsigned long)rate;
 }
 
 static long clk_factor_round_rate(struct clk_hw *hw, unsigned long rate,
-- 
2.47.3




More information about the barebox mailing list