Message ID | E1axXSV-0004hZ-CH@e0050434b2927.dyn.arm.linux.org.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 05/03/16 at 11:21am, Russell King wrote: > Fix warnings caused by selecting 64-bit file IO on 32-bit platforms. > > kexec/kexec.c:710:2: warning: format '%lx' expects argument of type 'long unsigned int', but argument 4 has type 'off_t' [-Wformat] > kexec/zlib.c:63:4: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'off_t' [-Wformat] > kexec/kexec-uImage.c:85:3: warning: format '%ld' expects argument of type 'long > int', but argument 2 has type 'off_t' [-Wformat] > > Signed-off-by: Russell King <rmk@arm.linux.org.uk> > --- > kexec/kexec-uImage.c | 3 ++- > kexec/kexec.c | 4 ++-- > kexec/zlib.c | 4 ++-- > 3 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/kexec/kexec-uImage.c b/kexec/kexec-uImage.c > index 9df601b..5e24629 100644 > --- a/kexec/kexec-uImage.c > +++ b/kexec/kexec-uImage.c > @@ -82,7 +82,8 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) > if (be32_to_cpu(header.ih_size) > len - sizeof(header)) { > printf("uImage header claims that image has %d bytes\n", > be32_to_cpu(header.ih_size)); > - printf("we read only %ld bytes.\n", len - sizeof(header)); > + printf("we read only %lld bytes.\n", > + (long long)len - sizeof(header)); With "D_FILE_OFFSET_BITS=64" adding, off_t is identical to off64_t, is that necessary to still take a type conversion here? Is that OK to be like this: printf("we read only %lld bytes.\n", len - sizeof(header));
On Sat, May 28, 2016 at 07:33:54PM +0800, Baoquan He wrote: > On 05/03/16 at 11:21am, Russell King wrote: > > diff --git a/kexec/kexec-uImage.c b/kexec/kexec-uImage.c > > index 9df601b..5e24629 100644 > > --- a/kexec/kexec-uImage.c > > +++ b/kexec/kexec-uImage.c > > @@ -82,7 +82,8 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) > > if (be32_to_cpu(header.ih_size) > len - sizeof(header)) { > > printf("uImage header claims that image has %d bytes\n", > > be32_to_cpu(header.ih_size)); > > - printf("we read only %ld bytes.\n", len - sizeof(header)); > > + printf("we read only %lld bytes.\n", > > + (long long)len - sizeof(header)); > > With "D_FILE_OFFSET_BITS=64" adding, off_t is identical to off64_t, is > that necessary to still take a type conversion here? The printf format specifies an argument of "long long" type, which is defined as a data type of at least 64-bits wide. So, it's more correct to cast to long long, rather than relying on off64_t being the same size as long long.
On 05/28/16 at 02:53pm, Russell King - ARM Linux wrote: > On Sat, May 28, 2016 at 07:33:54PM +0800, Baoquan He wrote: > > On 05/03/16 at 11:21am, Russell King wrote: > > > diff --git a/kexec/kexec-uImage.c b/kexec/kexec-uImage.c > > > index 9df601b..5e24629 100644 > > > --- a/kexec/kexec-uImage.c > > > +++ b/kexec/kexec-uImage.c > > > @@ -82,7 +82,8 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) > > > if (be32_to_cpu(header.ih_size) > len - sizeof(header)) { > > > printf("uImage header claims that image has %d bytes\n", > > > be32_to_cpu(header.ih_size)); > > > - printf("we read only %ld bytes.\n", len - sizeof(header)); > > > + printf("we read only %lld bytes.\n", > > > + (long long)len - sizeof(header)); > > > > With "D_FILE_OFFSET_BITS=64" adding, off_t is identical to off64_t, is > > that necessary to still take a type conversion here? > > The printf format specifies an argument of "long long" type, which is > defined as a data type of at least 64-bits wide. So, it's more > correct to cast to long long, rather than relying on off64_t being > the same size as long long. Ok, it's fine to have an explict cast here so that people don't need to consider off_t is long or long long. Ack this patch. Acked-by: Baoquan He <bhe@redhat.com> Thanks Baoquan
diff --git a/kexec/kexec-uImage.c b/kexec/kexec-uImage.c index 9df601b..5e24629 100644 --- a/kexec/kexec-uImage.c +++ b/kexec/kexec-uImage.c @@ -82,7 +82,8 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) if (be32_to_cpu(header.ih_size) > len - sizeof(header)) { printf("uImage header claims that image has %d bytes\n", be32_to_cpu(header.ih_size)); - printf("we read only %ld bytes.\n", len - sizeof(header)); + printf("we read only %lld bytes.\n", + (long long)len - sizeof(header)); return -1; } #ifdef HAVE_LIBZ diff --git a/kexec/kexec.c b/kexec/kexec.c index f0bd527..500e5a9 100644 --- a/kexec/kexec.c +++ b/kexec/kexec.c @@ -707,8 +707,8 @@ static int my_load(const char *type, int fileind, int argc, char **argv, /* slurp in the input kernel */ kernel_buf = slurp_decompress_file(kernel, &kernel_size); - dbgprintf("kernel: %p kernel_size: 0x%lx\n", - kernel_buf, kernel_size); + dbgprintf("kernel: %p kernel_size: %#llx\n", + kernel_buf, (unsigned long long)kernel_size); if (get_memory_ranges(&info.memory_range, &info.memory_ranges, info.kexec_flags) < 0 || info.memory_ranges == 0) { diff --git a/kexec/zlib.c b/kexec/zlib.c index 7170ac3..95b6080 100644 --- a/kexec/zlib.c +++ b/kexec/zlib.c @@ -60,8 +60,8 @@ char *zlib_decompress_file(const char *filename, off_t *r_size) if ((errno == EINTR) || (errno == EAGAIN)) continue; _gzerror(fp, &errnum, &msg); - dbgprintf("Read on %s of %ld bytes failed: %s\n", - filename, (allocated - size) + 0UL, msg); + dbgprintf("Read on %s of %d bytes failed: %s\n", + filename, (int)(allocated - size), msg); size = 0; goto fail; }
Fix warnings caused by selecting 64-bit file IO on 32-bit platforms. kexec/kexec.c:710:2: warning: format '%lx' expects argument of type 'long unsigned int', but argument 4 has type 'off_t' [-Wformat] kexec/zlib.c:63:4: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'off_t' [-Wformat] kexec/kexec-uImage.c:85:3: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'off_t' [-Wformat] Signed-off-by: Russell King <rmk@arm.linux.org.uk> --- kexec/kexec-uImage.c | 3 ++- kexec/kexec.c | 4 ++-- kexec/zlib.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)