diff mbox series

[kvm-unit-tests,v2,05/10] lib: x86: Use portable format macros for uint32_t

Message ID 20200901085056.33391-6-r.bolshakov@yadro.com (mailing list archive)
State New, archived
Headers show
Series Add support for generic ELF cross-compiler | expand

Commit Message

Roman Bolshakov Sept. 1, 2020, 8:50 a.m. UTC
Compilation of the files fails on ARCH=i386 with i686-elf gcc because
they use "%x" or "%d" format specifier that does not match the actual
size of uint32_t:

x86/s3.c: In function ‘main’:
x86/s3.c:53:35: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘u32’ {aka ‘long unsigned int’}
[-Werror=format=]
   53 |  printf("PM1a event registers at %x\n", fadt->pm1a_evt_blk);
      |                                  ~^     ~~~~~~~~~~~~~~~~~~
      |                                   |         |
      |                                   |         u32 {aka long unsigned int}
      |                                   unsigned int
      |                                  %lx

Use PRIx32 instead of "x" and PRId32 instead of "d" to take into account
u32_long case.

Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Cameron Esfahani <dirty@apple.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 lib/pci.c     | 2 +-
 x86/asyncpf.c | 2 +-
 x86/msr.c     | 3 ++-
 x86/s3.c      | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

Comments

Thomas Huth Sept. 4, 2020, 1:47 p.m. UTC | #1
On 01/09/2020 10.50, Roman Bolshakov wrote:
> Compilation of the files fails on ARCH=i386 with i686-elf gcc because
> they use "%x" or "%d" format specifier that does not match the actual
> size of uint32_t:
> 
> x86/s3.c: In function ‘main’:
> x86/s3.c:53:35: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘u32’ {aka ‘long unsigned int’}
> [-Werror=format=]
>    53 |  printf("PM1a event registers at %x\n", fadt->pm1a_evt_blk);
>       |                                  ~^     ~~~~~~~~~~~~~~~~~~
>       |                                   |         |
>       |                                   |         u32 {aka long unsigned int}
>       |                                   unsigned int
>       |                                  %lx
> 
> Use PRIx32 instead of "x" and PRId32 instead of "d" to take into account
> u32_long case.
> 
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Cc: Andrew Jones <drjones@redhat.com>
> Cc: Cameron Esfahani <dirty@apple.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>

Radim does not work at redhat.com anymore, so please remove that line in
case you respin the patch.

> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
> ---
>  lib/pci.c     | 2 +-
>  x86/asyncpf.c | 2 +-
>  x86/msr.c     | 3 ++-
>  x86/s3.c      | 2 +-
>  4 files changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>
diff mbox series

Patch

diff --git a/lib/pci.c b/lib/pci.c
index daa33e1..175caf0 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -248,7 +248,7 @@  void pci_bar_print(struct pci_dev *dev, int bar_num)
 		printf("BAR#%d,%d [%" PRIx64 "-%" PRIx64 " ",
 		       bar_num, bar_num + 1, start, end);
 	} else {
-		printf("BAR#%d [%02x-%02x ",
+		printf("BAR#%d [%02" PRIx32 "-%02" PRIx32 " ",
 		       bar_num, (uint32_t)start, (uint32_t)end);
 	}
 
diff --git a/x86/asyncpf.c b/x86/asyncpf.c
index 305a923..8239e16 100644
--- a/x86/asyncpf.c
+++ b/x86/asyncpf.c
@@ -78,7 +78,7 @@  static void pf_isr(struct ex_regs *r)
 			phys = 0;
 			break;
 		default:
-			report(false, "unexpected async pf reason %d", reason);
+			report(false, "unexpected async pf reason %" PRId32, reason);
 			break;
 	}
 }
diff --git a/x86/msr.c b/x86/msr.c
index f7539c3..ce5dabe 100644
--- a/x86/msr.c
+++ b/x86/msr.c
@@ -89,7 +89,8 @@  static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l
     wrmsr(msr_index, input);
     r = rdmsr(msr_index);
     if (expected != r) {
-        printf("testing %s: output = %#x:%#x expected = %#x:%#x\n", sptr,
+        printf("testing %s: output = %#" PRIx32 ":%#" PRIx32
+	       " expected = %#" PRIx32 ":%#" PRIx32 "\n", sptr,
                (u32)(r >> 32), (u32)r, (u32)(expected >> 32), (u32)expected);
     }
     report(expected == r, "%s", sptr);
diff --git a/x86/s3.c b/x86/s3.c
index da2d00c..6e41d0c 100644
--- a/x86/s3.c
+++ b/x86/s3.c
@@ -50,7 +50,7 @@  int main(int argc, char **argv)
 		*resume_vec++ = *addr;
 	printf("copy resume code from %p\n", &resume_start);
 
-	printf("PM1a event registers at %x\n", fadt->pm1a_evt_blk);
+	printf("PM1a event registers at %" PRIx32 "\n", fadt->pm1a_evt_blk);
 	outw(0x400, fadt->pm1a_evt_blk + 2);
 
 	/* Setup RTC alarm to wake up on the next second.  */