[PATCH] drivers: ddr: altera: Fix integer overflow during size calculation
Chee, Tien Fong
tien.fong.chee at altera.com
Tue Mar 11 04:57:36 CET 2025
> -----Original Message-----
> From: Ravulapalli, Naresh Kumar <naresh.kumar.ravulapalli at altera.com>
> Sent: Friday, March 7, 2025 6:29 PM
> To: u-boot at lists.denx.de
> Cc: Marek Vasut <marex at denx.de>; Simon Goldschmidt
> <simon.k.r.goldschmidt at gmail.com>; Chee, Tien Fong
> <tien.fong.chee at altera.com>; Meng, Tingting <tingting.meng at altera.com>;
> Tom Rini <trini at konsulko.com>; Ravulapalli, Naresh Kumar
> <naresh.kumar.ravulapalli at altera.com>
> Subject: [PATCH] drivers: ddr: altera: Fix integer overflow during size
> calculation
>
> Data structure, dramaddrw, is defined as u32. Compiler performs 32-bit
> arithmetic and logic operations on this data structure. Fix is provided to avoid
> integer overflow while performing shifting operations greater than 32-bit.
>
> Signed-off-by: Naresh Kumar Ravulapalli
> <nareshkumar.ravulapalli at altera.com>
> ---
> drivers/ddr/altera/sdram_soc64.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/ddr/altera/sdram_soc64.c
> b/drivers/ddr/altera/sdram_soc64.c
> index c8c9211adc..75c6de1e4e 100644
> --- a/drivers/ddr/altera/sdram_soc64.c
> +++ b/drivers/ddr/altera/sdram_soc64.c
> @@ -249,7 +249,7 @@ phys_size_t sdram_calculate_size(struct
> altera_sdram_plat *plat)
>
> DRAMADDRW_CFG_ROW_ADDR_WIDTH(dramaddrw) +
>
> DRAMADDRW_CFG_COL_ADDR_WIDTH(dramaddrw));
>
> - size *= (2 << (hmc_ecc_readl(plat, DDRIOCTRL) &
> + size *= ((phys_size_t)2 << (hmc_ecc_readl(plat, DDRIOCTRL) &
> DDR_HMC_DDRIOCTRL_IOSIZE_MSK));
>
> return size;
> --
> 2.35.3
Reviewed-by: Tien Fong Chee <tien.fong.chee at altera.com>
Best regards,
Tien Fong
More information about the U-Boot
mailing list