[U-Boot-Users] [PATCH] cmd_bdinfo: Fix printf() format warning

Fix the following warning on avr32 and, from the looks of it, all other architectures except arm, blackfin and mips.
cmd_bdinfo.c: In function 'do_bdinfo': cmd_bdinfo.c:367: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
In order to not introduce new warnings on the aforementioned three architectures as well as i386, I added a cast to unsigned long. This should be safe even if bi_baudrate is declared as 'int' (assuming there's no such thing as negative baud rates.)
Signed-off-by: Haavard Skinnemoen haavard.skinnemoen@atmel.com --- common/cmd_bdinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c index 24ff9b9..57c673c 100644 --- a/common/cmd_bdinfo.c +++ b/common/cmd_bdinfo.c @@ -364,7 +364,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } puts ("\nip_addr = "); print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %d bps\n", bd->bi_baudrate); + printf ("\nbaudrate = %lu bps\n", (unsigned long)bd->bi_baudrate);
return 0; }

In message 1217406953-11089-1-git-send-email-haavard.skinnemoen@atmel.com you wrote:
Fix the following warning on avr32 and, from the looks of it, all other architectures except arm, blackfin and mips.
cmd_bdinfo.c: In function 'do_bdinfo': cmd_bdinfo.c:367: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
In order to not introduce new warnings on the aforementioned three architectures as well as i386, I added a cast to unsigned long. This should be safe even if bi_baudrate is declared as 'int' (assuming there's no such thing as negative baud rates.)
Instead of the cast, should we not rather fix ARM, BF and MIPS to use ulong like anybody else?
Best regards,
Wolfgang Denk

Wolfgang Denk wd@denx.de wrote:
In order to not introduce new warnings on the aforementioned three architectures as well as i386, I added a cast to unsigned long. This should be safe even if bi_baudrate is declared as 'int' (assuming there's no such thing as negative baud rates.)
Instead of the cast, should we not rather fix ARM, BF and MIPS to use ulong like anybody else?
Yeah, that's probably better. But I don't know what sort of side effects that kind of change might cause. There could be code somewhere that needs bi_baudrate to be signed for some obscure reason.
But if you're ok with it and people are willing to test, I can certainly make that change.
Haavard

In message 20080730125755.060768a8@hskinnemo-gx745.norway.atmel.com you wrote:
Yeah, that's probably better. But I don't know what sort of side effects that kind of change might cause. There could be code somewhere that needs bi_baudrate to be signed for some obscure reason.
I am positively sure that no uch code exists (and it there were any such code it was worth of breaking it, really hard :-).
But if you're ok with it and people are willing to test, I can certainly make that change.
Please do.
Best regards,
Wolfgang Denk

Fix the following warning on avr32 and, from the looks of it, all other architectures except arm, blackfin and mips.
cmd_bdinfo.c: In function 'do_bdinfo': cmd_bdinfo.c:367: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
In order to not introduce new warnings on the aforementioned three architectures as well as i386, I changed the type of the bi_baudrate field to be unsigned long so that all architectures are consisten. This may break some really questionable code (highly unlikely) and/or introduce new format warnings elsewhere (somewhat more likely), but if so, it needs fixing anyway.
Signed-off-by: Haavard Skinnemoen haavard.skinnemoen@atmel.com Cc: Jean-Christophe Plagniol-Villard plagnioj@jcrosoft.com Cc: Mike Frysinger vapier@gentoo.org Cc: Shinya Kuribayashi skuribay@ruby.dti.ne.jp --- Cc'ed the maintainers of the affected architectures except i386.
Does anyone know who's in charge of the i386 port? The chances of breakage on i386 is lower than on the other three architectures since the field is unsigned to begin with, and is wedged between two other unsigned longs, so it shouldn't cause any changes to the struct layout even on x86_64.
common/cmd_bdinfo.c | 2 +- include/asm-arm/u-boot.h | 2 +- include/asm-blackfin/u-boot.h | 2 +- include/asm-i386/u-boot.h | 2 +- include/asm-mips/u-boot.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c index 24ff9b9..b38f43c 100644 --- a/common/cmd_bdinfo.c +++ b/common/cmd_bdinfo.c @@ -364,7 +364,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } puts ("\nip_addr = "); print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %d bps\n", bd->bi_baudrate); + printf ("\nbaudrate = %lu bps\n", bd->bi_baudrate);
return 0; } diff --git a/include/asm-arm/u-boot.h b/include/asm-arm/u-boot.h index b11d555..8c739ff 100644 --- a/include/asm-arm/u-boot.h +++ b/include/asm-arm/u-boot.h @@ -37,7 +37,7 @@ #define _U_BOOT_H_ 1
typedef struct bd_info { - int bi_baudrate; /* serial console baudrate */ + unsigned long bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; /* IP Address */ unsigned char bi_enetaddr[6]; /* Ethernet adress */ struct environment_s *bi_env; diff --git a/include/asm-blackfin/u-boot.h b/include/asm-blackfin/u-boot.h index 9d2903b..a3907ec 100644 --- a/include/asm-blackfin/u-boot.h +++ b/include/asm-blackfin/u-boot.h @@ -29,7 +29,7 @@ #define _U_BOOT_H_ 1
typedef struct bd_info { - int bi_baudrate; /* serial console baudrate */ + unsigned long bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; /* IP Address */ unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_boot_params; /* where this board expects params */ diff --git a/include/asm-i386/u-boot.h b/include/asm-i386/u-boot.h index fc5a2ae..1276e39 100644 --- a/include/asm-i386/u-boot.h +++ b/include/asm-i386/u-boot.h @@ -50,7 +50,7 @@ typedef struct bd_info { unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ unsigned long bi_intfreq; /* Internal Freq, in MHz */ unsigned long bi_busfreq; /* Bus Freq, in MHz */ - unsigned int bi_baudrate; /* Console Baudrate */ + unsigned long bi_baudrate; /* Console Baudrate */ unsigned long bi_boot_params; /* where this board expects params */ struct environment_s *bi_env; struct /* RAM configuration */ diff --git a/include/asm-mips/u-boot.h b/include/asm-mips/u-boot.h index 9ecb9ac..c40afd7 100644 --- a/include/asm-mips/u-boot.h +++ b/include/asm-mips/u-boot.h @@ -32,7 +32,7 @@ #define _U_BOOT_H_ 1
typedef struct bd_info { - int bi_baudrate; /* serial console baudrate */ + unsigned long bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; /* IP Address */ unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_arch_number; /* unique id for this board */

Haavard Skinnemoen haavard.skinnemoen@atmel.com wrote:
Fix the following warning on avr32 and, from the looks of it, all other architectures except arm, blackfin and mips.
cmd_bdinfo.c: In function 'do_bdinfo': cmd_bdinfo.c:367: warning: format '%d' expects type 'int', but argument 2 has type 'long unsigned int'
Ah, bugger. I completely misparsed that file -- do_bdinfo is supposed to be arch-specific, but avr32 uses the same implementation as MIPS for some arbitrary reason. So this patch just makes things worse.
Please ignore. I'll fix it some other way.
Btw, how about moving this stuff into an arch-specific file? lib_<arch>/bdinfo.c for example?
Haavard
participants (2)
-
Haavard Skinnemoen
-
Wolfgang Denk