Re: [PATCH 05/10] clk: divider: Avoid division by zero in _div_round_closest()
From: Brian Masney
Date: Tue Nov 24 2026 - 12:36:23 EST
Hi Lee,
On Mon, Nov 23, 2026 at 04:47:38PM +0000, Lee Jones wrote:
> 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;
> +
Carlo Caione posted a separate fix for this that I merged yesterday.
Patch 2 in his series covers what you posted.
https://lore.kernel.org/linux-clk/20261119-upstream-clk-divider-large-rates-v3-0-838eccd2e497@xxxxxxxxxxxx/
Brian