diff mbox

[U-Boot] powerpc: tqm834x: Fix build warnings in initdram()

Message ID 1453710595-26324-1-git-send-email-bmeng.cn@gmail.com
State Accepted
Commit 4019e54dc69ef088a46ef644b9cc2deee498c148
Delegated to: Tom Rini
Headers show

Commit Message

Bin Meng Jan. 25, 2016, 8:29 a.m. UTC
With gcc 4.9, it produces the following warnings:

  CC      board/tqc/tqm834x/tqm834x.o
  board/tqc/tqm834x/tqm834x.c: In function 'initdram':
  board/tqc/tqm834x/tqm834x.c:325:12: warning: iteration 3u invokes undefined behavior [-Waggressive-loop-optimizations]
      (((base + size - 1) >> CSBNDS_EA_SHIFT) &
              ^
  board/tqc/tqm834x/tqm834x.c:80:2: note: containing loop
      for(cs = 0; cs < 4; ++cs) {
      ^

There is an integer overflow when cs = 3. To fix it, change
parameters of set_cs_bounds() to ulong.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 board/tqc/tqm834x/tqm834x.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tom Rini Jan. 25, 2016, 9:30 p.m. UTC | #1
On Mon, Jan 25, 2016 at 12:29:55AM -0800, Bin Meng wrote:

> With gcc 4.9, it produces the following warnings:
> 
>   CC      board/tqc/tqm834x/tqm834x.o
>   board/tqc/tqm834x/tqm834x.c: In function 'initdram':
>   board/tqc/tqm834x/tqm834x.c:325:12: warning: iteration 3u invokes undefined behavior [-Waggressive-loop-optimizations]
>       (((base + size - 1) >> CSBNDS_EA_SHIFT) &
>               ^
>   board/tqc/tqm834x/tqm834x.c:80:2: note: containing loop
>       for(cs = 0; cs < 4; ++cs) {
>       ^
> 
> There is an integer overflow when cs = 3. To fix it, change
> parameters of set_cs_bounds() to ulong.
> 
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/board/tqc/tqm834x/tqm834x.c b/board/tqc/tqm834x/tqm834x.c
index d891a38..eca218c 100644
--- a/board/tqc/tqm834x/tqm834x.c
+++ b/board/tqc/tqm834x/tqm834x.c
@@ -43,7 +43,7 @@  ulong flash_get_size (ulong base, int banknum);
 /* Local functions */
 static int detect_num_flash_banks(void);
 static long int get_ddr_bank_size(short cs, long *base);
-static void set_cs_bounds(short cs, long base, long size);
+static void set_cs_bounds(short cs, ulong base, ulong size);
 static void set_cs_config(short cs, long config);
 static void set_ddr_config(void);
 
@@ -314,7 +314,7 @@  static long int get_ddr_bank_size(short cs, long *base)
 /**************************************************************************
  * Sets DDR bank CS bounds.
  */
-static void set_cs_bounds(short cs, long base, long size)
+static void set_cs_bounds(short cs, ulong base, ulong size)
 {
 	debug("Setting bounds %08lx, %08lx for cs %d\n", base, size, cs);
 	if(size == 0){