[PATCH 05/10] clk: divider: Avoid division by zero in _div_round_closest()

From: Lee Jones

Date: Mon Nov 23 2026 - 11:49:54 EST


When CLK_SET_RATE_PARENT is not set on a CLK_DIVIDER_ROUND_CLOSEST
divider, clk_divider_bestdiv() invokes _div_round_closest() before
clamping the resulting divisor to at least 1. If the requested rate
exceeds parent_rate (for instance via clk_round_rate(clk, ULONG_MAX))
or parent_rate is zero, parent_rate / rate evaluates to 0.

Passing down == 0 into __rounddown_pow_of_two() triggers an undefined
shift and truncates back to 0, after which DIV_ROUND_UP_ULL() divides by
zero.

Since a divider cannot increase its parent rate, return the minimum
valid divisor directly whenever rate is greater than or equal to
parent_rate.

Fixes: 9315514252a9 ("clk: divider: fix calculation of initial best divider when rounding to closest")
Closes: https://sashiko.dev/#/bug/linux-cc7c0851-a317-4348-ab29-9d748aa20cfc
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/clk/clk-divider.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index f68216c65d3d..d05dc595ec4c 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -244,6 +244,9 @@ static int _div_round_closest(const struct clk_div_table *table,
int up, down;
unsigned long up_rate, down_rate;

+ if (rate >= parent_rate)
+ return table ? _round_up_table(table, 1) : 1;
+
up = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
down = parent_rate / rate;

--
2.56.1.750.gf70dc682cf-goog