* [PATCH] ddr: socfpga: Fix integer overflow that caused DDR size mismatched
@ 2020-08-05 3:58 tien.fong.chee at intel.com
2020-08-05 9:31 ` Tan, Ley Foon
0 siblings, 1 reply; 2+ messages in thread
From: tien.fong.chee at intel.com @ 2020-08-05 3:58 UTC (permalink / raw)
To: u-boot
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(-)
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;
--
2.13.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] ddr: socfpga: Fix integer overflow that caused DDR size mismatched
2020-08-05 3:58 [PATCH] ddr: socfpga: Fix integer overflow that caused DDR size mismatched tien.fong.chee at intel.com
@ 2020-08-05 9:31 ` Tan, Ley Foon
0 siblings, 0 replies; 2+ messages in thread
From: Tan, Ley Foon @ 2020-08-05 9:31 UTC (permalink / raw)
To: u-boot
> -----Original Message-----
> From: Chee, Tien Fong <tien.fong.chee@intel.com>
> Sent: Wednesday, August 5, 2020 11:59 AM
> To: u-boot at 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-05 9:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05 3:58 [PATCH] ddr: socfpga: Fix integer overflow that caused DDR size mismatched tien.fong.chee at intel.com
2020-08-05 9:31 ` Tan, Ley Foon
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.