Message ID | 20200420223418.117186-6-mhorne@FreeBSD.org |
---|---|
State | New |
Headers | show |
Series | Add support for CONFIG_API on RISC-V | expand |
On Tue, Apr 21, 2020 at 7:28 AM <mhorne at freebsd.org> wrote: > > From: Mitchell Horne <mhorne at FreeBSD.org> > > 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 <mhorne at FreeBSD.org> > --- > 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", Use LBAF from include/blk.h ? Also I am not sure why CONFIG_SYS_64BIT_LBA is undefined in include/api_public.h ? > + (uint64_t)di->di_stor.block_count); > } > } Regards, Bin
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); } }