Re: [PATCH] clk: imx: pll14xx: Fix potential integer overflow

From: Frank Li

Date: Thu Nov 05 2026 - 14:07:36 EST


On Thu, Nov 05, 2026 at 11:46:32AM +0200, Stefan Ghetu wrote:
> [You don't often get email from stefan.ghetu@xxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Florin Pavelescu <florin.pavelescu@xxxxxxx>
>
> Cast to u64, so that multiplications and additions will be done
> in 64-bit arithmetic (and the results will also be 64-bit)
> and the possibility of integer overflow is eliminated.
>
> Fixes: 53990cf9d5b48 ("clk: imx: pll14xx: consolidate rate calculation")
> Signed-off-by: Florin Pavelescu <florin.pavelescu@xxxxxxx>
> Signed-off-by: Stefan Ghetu <stefan.ghetu@xxxxxxx>
> ---
> drivers/clk/imx/clk-pll14xx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c
> index c6438144e507..08f9d3fbc75f 100644
> --- a/drivers/clk/imx/clk-pll14xx.c
> +++ b/drivers/clk/imx/clk-pll14xx.c
> @@ -124,7 +124,7 @@ static long pll14xx_calc_rate(struct clk_pll14xx *pll, int mdiv, int pdiv,
> u64 fout = prate;
>
> /* fout = (m * 65536 + k) * Fin / (p * 65536) / (1 << sdiv) */
> - fout *= (mdiv * 65536 + kdiv);
> + fout *= ((u64)mdiv * 65536 + (u64)kdiv);

suppose only need one cast. u64 + u32 will convert u64 + u64 automatically.

Frank
> pdiv *= 65536;
>
> do_div(fout, pdiv << sdiv);
> --
> 2.34.1
>
>