Skip to contentSkip to conversation

cmd_bdinfo: Fix printf() format warning

PATCH New Haavard Skinnemoen 2 participants 6 messages Jul 30, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.)

---
 common/cmd_bdinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
common/cmd_bdinfo.c +1 -1
index 24ff9b9..57c673c 100644
@@ -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;
 }
Signature · 1 line
1.5.6.2
#1 lore raw

PATCH 1/1 cmd_bdinfo: Fix printf() format warning

Quoted 11 lines · In message <[email protected]>…

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

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
We Klingons believe as you do -- the sick should die. Only the strong
should live.
	-- Kras, "Friday's Child", stardate 3497.2
#2 lore raw

PATCH 1/1 cmd_bdinfo: Fix printf() format warning

Quoted 7 lines · Wolfgang Denk
Quoted 4 lines

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

#3 lore raw

PATCH 1/1 cmd_bdinfo: Fix printf() format warning

Quoted 4 lines · In message <[email protected]> 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 :-).

Quoted 2 lines

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

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It seems intuitively obvious to me, which  means  that  it  might  be
wrong.                                                 -- Chris Torek
#4 lore raw

PATCH v2 1/1 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 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.

Cc Jean-Christophe Plagniol-Villard <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Shinya Kuribayashi <[email protected]>

---
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(-)
common/cmd_bdinfo.c +1 -1
index 24ff9b9..b38f43c 100644
@@ -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;
 }
include/asm-arm/u-boot.h +1 -1
index b11d555..8c739ff 100644
@@ -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;
include/asm-blackfin/u-boot.h +1 -1
index 9d2903b..a3907ec 100644
@@ -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 */
include/asm-i386/u-boot.h +1 -1
index fc5a2ae..1276e39 100644
@@ -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 */
include/asm-mips/u-boot.h +1 -1
index 9ecb9ac..c40afd7 100644
@@ -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 */
Signature · 1 line
1.5.6.3
#5 lore raw

PATCH v2 1/1 cmd_bdinfo: Fix printf() format warning

Quoted 6 lines · Haavard Skinnemoen

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