Skip to contentSkip to conversation

clk: imx: pll14xx: Fix potential integer overflow

PATCH RESEND New Stefan Ghetu 1 participant 1 message Nov 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v3 1/1 clk: imx: pll14xx: Fix potential integer overflow

From: Florin Pavelescu <[email protected]>

Cast to u64, so that multiplications and additions will be done in 64-bit arithmetic and the possibility of integer overflow is eliminated.

To silence the Coverity warning.

---
Changes in v2:
- Drop the redundant (u64) cast on kdiv, as suggested by Frank Li. Adding a 32-bit value to a u64 already promotes it to u64.
Changes in v3:
- Drop the Fixes tag

 drivers/clk/imx/clk-pll14xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/imx/clk-pll14xx.c +1 -1
index c6438144e507..ee9a9e4c392a 100644
@@ -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 + kdiv);
 	pdiv *= 65536;
 
 	do_div(fout, pdiv << sdiv);
Signature · 1 line
2.34.1