From: Andrew Jones Subject: [kvm-unit-tests PATCH v3 2/4] lib/alloc: fix format warnings, add/use PRIx64 Date: Thu, 3 Mar 2016 13:33:06 +0100 Message-ID: <1457008388-12749-3-git-send-email-drjones@redhat.com> References: <1457008388-12749-1-git-send-email-drjones@redhat.com> Cc: thuth@redhat.com, pbonzini@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:49335 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754802AbcCCMdW (ORCPT ); Thu, 3 Mar 2016 07:33:22 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 07D1B46A for ; Thu, 3 Mar 2016 12:33:22 +0000 (UTC) In-Reply-To: <1457008388-12749-1-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Also add casts, in case phys_addr_t is only a u32. Signed-off-by: Andrew Jones --- lib/alloc.c | 25 ++++++++++++++----------- lib/libcflat.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/alloc.c b/lib/alloc.c index 34f71a337d868..e1d7b8a380ff8 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -28,13 +28,15 @@ void phys_alloc_show(void) int i; spin_lock(&lock); - printf("phys_alloc minimum alignment: 0x%llx\n", align_min); + printf("phys_alloc minimum alignment: 0x%" PRIx64 "\n", + (u64)align_min); for (i = 0; i < nr_regions; ++i) - printf("%016llx-%016llx [%s]\n", - regions[i].base, - regions[i].base + regions[i].size - 1, + printf("%016" PRIx64 "-%016" PRIx64 " [%s]\n", + (u64)regions[i].base, + (u64)(regions[i].base + regions[i].size - 1), "USED"); - printf("%016llx-%016llx [%s]\n", base, top - 1, "FREE"); + printf("%016" PRIx64 "-%016" PRIx64 " [%s]\n", + (u64)base, (u64)(top - 1), "FREE"); spin_unlock(&lock); } @@ -68,7 +70,7 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, top_safe = top; if (safe && sizeof(long) == 4) - top_safe = MIN(top, 1ULL << 32); + top_safe = MIN(top_safe, 1ULL << 32); align = MAX(align, align_min); @@ -76,11 +78,12 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, size += addr - base; if ((top_safe - base) < size) { - printf("phys_alloc: requested=0x%llx (align=0x%llx), " - "need=0x%llx, but free=0x%llx. " - "top=0x%llx, top_safe=0x%llx\n", - size_orig, align, size, top_safe - base, - top, top_safe); + printf("phys_alloc: requested=0x%" PRIx64 + " (align=0x%" PRIx64 "), " + "need=0x%" PRIx64 ", but free=0x%" PRIx64 ". " + "top=0x%" PRIx64 ", top_safe=0x%" PRIx64 "\n", + (u64)size_orig, (u64)align, (u64)size, top_safe - base, + (u64)top, top_safe); spin_unlock(&lock); return INVALID_PHYS_ADDR; } diff --git a/lib/libcflat.h b/lib/libcflat.h index 59c9c6e3b0d91..b58a8a1954eff 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -48,6 +48,18 @@ typedef _Bool bool; #define false 0 #define true 1 +#if __SIZEOF_LONG__ == 8 +# define __PRI64_PREFIX "l" +# define __PRIPTR_PREFIX "l" +#else +# define __PRI64_PREFIX "ll" +# define __PRIPTR_PREFIX +#endif +#define PRId64 __PRI64_PREFIX "d" +#define PRIu64 __PRI64_PREFIX "u" +#define PRIx64 __PRI64_PREFIX "x" +#define PRIxPTR __PRIPTR_PREFIX "x" + extern void puts(const char *s); extern void exit(int code); extern void abort(void); -- 2.4.3