[PATCH v4 7/8] clk: clocking-wizard: Fix division by zero and unbounded register write

Brian Masney masneyb at kernel.org
Wed Nov 25 07:36:33 PST 2026


Hi Shubhrajyoti,

> 1. clk_wzrd_determine_rate(): DIV_ROUND_CLOSEST() can return 0 when
>    the requested rate greatly exceeds the parent rate, causing a
>    division by zero on the subsequent parent_rate / div. Clamp div
>    to a minimum of 1.
> 
> 2. clk_wzrd_dynamic_reconfig(): min_t() result was not assigned back
>    to value, so the cap to WZRD_DR_MAX_INT_DIV_VALUE was never applied
>    before the register write.
> 
> 3. clk_wzrd_get_divisors() and clk_wzrd_get_divisors_ver(): If rate is
>    0, DIV_ROUND_CLOSEST_ULL divides by zero. Return -EINVAL early.
> 
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta at amd.com>

This needs some Fixes tag(s) and Cc for stable. Also this, and the last
patch needs to go at the beginning of the series to make it easier to
backport to the stable kernels.

> ---
> (no changes since v2)
> 
> Changes in v2:
> - New patch
> 
>  drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
> index 7fe8d0d4cfba..046efa5c77c9 100644
> --- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
> +++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
> @@ -303,7 +303,7 @@ static int clk_wzrd_dynamic_reconfig(struct clk_hw *hw, unsigned long rate,
>  	value = DIV_ROUND_CLOSEST(parent_rate, rate);
>  
>  	/* Cap the value to max */
> -	min_t(u32, value, WZRD_DR_MAX_INT_DIV_VALUE);
> +	value = min_t(u32, value, WZRD_DR_MAX_INT_DIV_VALUE);
>  
>  	/* Set divisor and clear phase offset */
>  	writel(value, div_addr);
> @@ -341,6 +341,8 @@ static int clk_wzrd_determine_rate(struct clk_hw *hw,
>  	 * achievable
>  	 */
>  	div = DIV_ROUND_CLOSEST(req->best_parent_rate, req->rate);

The Sashiko feedback looks legit here regarding the u8.

Brian

-- 
Brian Masney <masneyb at kernel.org>



More information about the linux-arm-kernel mailing list