From: Ahmad Fatoum <[email protected]>

clk_divider_bestdiv() compares candidates with a truncating division,
while divider_recalc_rate() rounds up. The search thus accepts a divider
whose reported rate is 1 Hz above the request, making clk_round_rate()
non-idempotent. Use DIV_ROUND_UP_ULL() there as well, as Linux commit
b11d282dbea2 ("clk: divider: fix rate calculation for fractional
rates") does; its other hunks barebox already has.

On i.MX6, clk_round_rate(ipu1_di0, 65 MHz) now yields 64800000 instead
of 40500000.

Fixes: e27c0b64db01 ("clk: add divider_recalc_rate helper")
Reported-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 drivers/clk/clk-divider.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 97dc9679c91c..8e630ccde4e6 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -213,7 +213,7 @@ static int clk_divider_bestdiv(struct clk *clk, unsigned 
long rate,
                }
                parent_rate = clk_round_rate(clk_get_parent(clk),
                                MULT_ROUND_UP(rate, i));
-               now = parent_rate / i;
+               now = DIV_ROUND_UP_ULL((u64)parent_rate, i);
                if (now <= rate && now > best) {
                        bestdiv = i;
                        best = now;
-- 
2.47.3


Reply via email to