Re: [PATCH v2 2/3] clk: divider: Fix round-closest for rates above the parent rate

From: Sebastian Reichel

Date: Thu Nov 12 2026 - 10:54:36 EST


Hi,

On Thu, Nov 12, 2026 at 10:37:00AM +0100, Carlo Caione wrote:
> When the requested rate is above the parent rate, _div_round_closest()
> computes a down divider of 0 and divides the parent rate by it. Asking a
> CLK_DIVIDER_ROUND_CLOSEST divider without CLK_SET_RATE_PARENT for its
> maximum rate with clk_round_rate(clk, ULONG_MAX) then traps on x86.
>
> No divider goes above the parent rate, so the smallest one is the
> closest. Return it before dividing.
>
> Fixes: 26bac95aa88c ("clk: divider: fix selection of divider when rounding to closest")
> Signed-off-by: Carlo Caione <ccaione@xxxxxxxxxxxx>
> ---

Reviewed-by: Sebastian Reichel <sebastian.reichel@xxxxxxxxxxxxx>

Greetings,

-- Sebastian

> drivers/clk/clk-divider.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index c3f46f9ee451..ed60fa9b04fa 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -254,6 +254,11 @@ static int _div_round_closest(const struct clk_div_table *table,
> int up, down;
> unsigned long up_rate, down_rate;
>
> + /* No divider goes above the parent rate: the smallest one is the closest */
> + if (rate >= parent_rate)
> + return table && !(flags & CLK_DIVIDER_POWER_OF_TWO) ?
> + _get_table_mindiv(table) : 1;
> +
> up = _get_div_round_up(parent_rate, rate);
> down = parent_rate / rate;
>
>
> --
> 2.56.0
>

Attachment: signature.asc
Description: PGP signature