diff mbox series

ddr: socfpga: Fix integer overflow that caused DDR size mismatched

Message ID 20200805035840.22467-1-tien.fong.chee@intel.com
State New
Delegated to: Simon Goldschmidt
Headers show
Series ddr: socfpga: Fix integer overflow that caused DDR size mismatched | expand

Commit Message

Chee, Tien Fong Aug. 5, 2020, 3:58 a.m. UTC
From: Tien Fong Chee <tien.fong.chee@intel.com>

Convert the constant integer to 'phys_size_t' to avoid overflow
when calculating the SDRAM size.

Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
---
 drivers/ddr/altera/sdram_soc64.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Ley Foon Tan Aug. 5, 2020, 9:31 a.m. UTC | #1
> -----Original Message-----
> From: Chee, Tien Fong <tien.fong.chee@intel.com>
> Sent: Wednesday, August 5, 2020 11:59 AM
> To: u-boot@lists.denx.de
> Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>; Marek Vasut
> <marex@denx.de>; See, Chin Liang <chin.liang.see@intel.com>; Tan, Ley
> Foon <ley.foon.tan@intel.com>; Lim, Elly Siew Chin
> <elly.siew.chin.lim@intel.com>; Ang, Chee Hong
> <chee.hong.ang@intel.com>; Chee, Tien Fong <tien.fong.chee@intel.com>
> Subject: [PATCH] ddr: socfpga: Fix integer overflow that caused DDR size
> mismatched
> 
> From: Tien Fong Chee <tien.fong.chee@intel.com>
> 
> Convert the constant integer to 'phys_size_t' to avoid overflow when
> calculating the SDRAM size.
> 
> Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
> ---
>  drivers/ddr/altera/sdram_soc64.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)


Reviewed-by: Ley Foon Tan <ley.foon.tan@intel.com>

Regards
Ley Foon
diff mbox series

Patch

diff --git a/drivers/ddr/altera/sdram_soc64.c b/drivers/ddr/altera/sdram_soc64.c
index 8cb75fe02a..a862ac8092 100644
--- a/drivers/ddr/altera/sdram_soc64.c
+++ b/drivers/ddr/altera/sdram_soc64.c
@@ -218,13 +218,14 @@  phys_size_t sdram_calculate_size(struct altera_sdram_platdata *plat)
 {
 	u32 dramaddrw = hmc_readl(plat, DRAMADDRW);
 
-	phys_size_t size = 1 << (DRAMADDRW_CFG_CS_ADDR_WIDTH(dramaddrw) +
-			 DRAMADDRW_CFG_BANK_GRP_ADDR_WIDTH(dramaddrw) +
-			 DRAMADDRW_CFG_BANK_ADDR_WIDTH(dramaddrw) +
-			 DRAMADDRW_CFG_ROW_ADDR_WIDTH(dramaddrw) +
-			 DRAMADDRW_CFG_COL_ADDR_WIDTH(dramaddrw));
-
-	size *= (2 << (hmc_ecc_readl(plat, DDRIOCTRL) &
+	phys_size_t size = (phys_size_t)1 <<
+			   (DRAMADDRW_CFG_CS_ADDR_WIDTH(dramaddrw) +
+			    DRAMADDRW_CFG_BANK_GRP_ADDR_WIDTH(dramaddrw) +
+			    DRAMADDRW_CFG_BANK_ADDR_WIDTH(dramaddrw) +
+			    DRAMADDRW_CFG_ROW_ADDR_WIDTH(dramaddrw) +
+			    DRAMADDRW_CFG_COL_ADDR_WIDTH(dramaddrw));
+
+	size *= ((phys_size_t)2 << (hmc_ecc_readl(plat, DDRIOCTRL) &
 			DDR_HMC_DDRIOCTRL_IOSIZE_MSK));
 
 	return size;