[PATCH 07/18] clk: imx: pll14xx: potential integer overflow eliminated by casting to u64

From: Peng Fan (OSS)
Date: Fri May 03 2024 - 20:42:45 EST


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.

Fix Unintentional integer overflow reported by Coverity

Reviewed-by: Viorel Suman <viorel.suman@xxxxxxx>
Signed-off-by: Florin Pavelescu <florin.pavelescu@xxxxxxx>
Signed-off-by: Peng Fan <peng.fan@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 6b2c849f8b71..78eedb1f4a79 100644
--- a/drivers/clk/imx/clk-pll14xx.c
+++ b/drivers/clk/imx/clk-pll14xx.c
@@ -118,7 +118,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);
pdiv *= 65536;

do_div(fout, pdiv << sdiv);

--
2.37.1