diff mbox series

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

Message ID 20240504-imx-clk-v1-7-f7915489d58d@nxp.com (mailing list archive)
State Superseded
Headers show
Series clk: imx: misc update/fix | expand

Commit Message

Peng Fan (OSS) May 4, 2024, 12:49 a.m. UTC
From: Florin Pavelescu <florin.pavelescu@nxp.com>

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@nxp.com>
Signed-off-by: Florin Pavelescu <florin.pavelescu@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/clk/imx/clk-pll14xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Francesco Dolcini May 4, 2024, 11:58 a.m. UTC | #1
Hello Peng,

On Sat, May 04, 2024 at 08:49:00AM +0800, Peng Fan (OSS) wrote:
> From: Florin Pavelescu <florin.pavelescu@nxp.com>
> 
> 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

Fixes tag if this is a fix?

It would be interesting in general if this can be trigger in real life
and with which side effects or if we are just silencing the tool
Peng Fan May 4, 2024, 1:13 p.m. UTC | #2
> Subject: Re: [PATCH 07/18] clk: imx: pll14xx: potential integer overflow
> eliminated by casting to u64
> 
> Hello Peng,
> 
> On Sat, May 04, 2024 at 08:49:00AM +0800, Peng Fan (OSS) wrote:
> > From: Florin Pavelescu <florin.pavelescu@nxp.com>
> >
> > 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
> 
> Fixes tag if this is a fix?
> 
> It would be interesting in general if this can be trigger in real life and with
> which side effects or if we are just silencing the tool

This is just to silencing the tool, maybe this patch is no needed.

Thanks,
Peng.
diff mbox series

Patch

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);