From patchwork Mon Apr 20 22:34:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitchell Horne X-Patchwork-Id: 238135 List-Id: U-Boot discussion From: mhorne at FreeBSD.org (mhorne at FreeBSD.org) Date: Mon, 20 Apr 2020 18:34:16 -0400 Subject: [PATCH 5/7] examples: fix incompatible type casts In-Reply-To: <20200420223418.117186-1-mhorne@FreeBSD.org> References: <20200420223418.117186-1-mhorne@FreeBSD.org> Message-ID: <20200420223418.117186-6-mhorne@FreeBSD.org> From: Mitchell Horne Some printf statements in the API demo assume pointers to be 32-bits long, presumably since it was originally developed for 32-bit arm. This generates a number of warnings when compiling for 64-bit architectures, and may result in truncation of these values. Fix this by avoiding casts where possible or casting to a more appropriate type. Signed-off-by: Mitchell Horne --- examples/api/demo.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/api/demo.c b/examples/api/demo.c index e7523786b4..f81466c5cf 100644 --- a/examples/api/demo.c +++ b/examples/api/demo.c @@ -43,12 +43,12 @@ int main(int argc, char * const argv[]) if (sig->version > API_SIG_VERSION) return -3; - printf("API signature found @%x\n", (unsigned int)sig); + printf("API signature found @%lx\n", (uintptr_t)sig); test_dump_sig(sig); printf("\n*** Consumer API test ***\n"); - printf("syscall ptr 0x%08x@%08x\n", (unsigned int)syscall_ptr, - (unsigned int)&syscall_ptr); + printf("syscall ptr 0x%08lx@%08lx\n", (uintptr_t)syscall_ptr, + (uintptr_t)&syscall_ptr); /* console activities */ ub_putc('B'); @@ -203,7 +203,7 @@ void test_dump_sig(struct api_signature *sig) printf("signature:\n"); printf(" version\t= %d\n", sig->version); printf(" checksum\t= 0x%08x\n", sig->checksum); - printf(" sc entry\t= 0x%08x\n", (unsigned int)sig->syscall); + printf(" sc entry\t= 0x%08lx\n", (uintptr_t)sig->syscall); } void test_dump_si(struct sys_info *si) @@ -211,9 +211,9 @@ void test_dump_si(struct sys_info *si) int i; printf("sys info:\n"); - printf(" clkbus\t= 0x%08x\n", (unsigned int)si->clk_bus); - printf(" clkcpu\t= 0x%08x\n", (unsigned int)si->clk_cpu); - printf(" bar\t\t= 0x%08x\n", (unsigned int)si->bar); + printf(" clkbus\t= 0x%08lx\n", si->clk_bus); + printf(" clkcpu\t= 0x%08lx\n", si->clk_cpu); + printf(" bar\t\t= 0x%08lx\n", si->bar); printf("---\n"); for (i = 0; i < si->mr_no; i++) { @@ -296,7 +296,7 @@ void test_dump_di(int handle) struct device_info *di = ub_dev_get(handle); printf("device info (%d):\n", handle); - printf(" cookie\t= 0x%08x\n", (uint32_t)di->cookie); + printf(" cookie\t= 0x%08lx\n", (uintptr_t)di->cookie); printf(" type\t\t= 0x%08x\n", di->type); if (di->type == DEV_TYP_NET) { @@ -308,7 +308,8 @@ void test_dump_di(int handle) } else if (di->type & DEV_TYP_STOR) { printf(" type\t\t= %s\n", test_stor_typ(di->type)); - printf(" blk size\t\t= %d\n", (unsigned int)di->di_stor.block_size); - printf(" blk count\t\t= %d\n", (unsigned int)di->di_stor.block_count); + printf(" blk size\t\t= %lu\n", di->di_stor.block_size); + printf(" blk count\t\t= %llu\n", + (uint64_t)di->di_stor.block_count); } }