drivers/char/random.c:827:3: warning: format '%zd' expects argument of type 'signed size_t', but argument 7 has type 'size_t'
A message that is not in the archive (sent off-list or not yet received): 20121023101658.GC10451@localhost
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20121024005612.GA4028@localhost
[add CC to mn10300/cris arch lists]
Quoted 28 lines · Fengguang Wu
Quoted 27 lines · Andrew Morton
Quoted 23 lines · On Tue, 23 Oct 2012 18:16:58 +0800 Fengguang Wu <[email protected]> wrote:
Hi Jiri,
FYI, there are new compile warnings show up in
tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm head: dbfe0815b4af06cc4ca6cd12b17e2d13ffaaf991 commit: 0b1f5a647784c406ee33a6ddd3bb6382a2278111 [155/157] random: fix debug format strings config: mn10300-asb2364_defconfig # make ARCH=mn10300 asb2364_defconfigAll warnings:
drivers/char/random.c: In function 'xfer_secondary_pool':drivers/char/random.c:827:3: warning: format '%zd' expects argument of type 'signedsize_t', but argument 7 has type 'size_t' [-Wformat]drivers/char/random.c: In function 'account':drivers/char/random.c:859:2: warning: format '%zd' expects argument of type 'signedsize_t', but argument 5 has type 'size_t' [-Wformat]drivers/char/random.c:881:2: warning: format '%zd' expects argument of type 'signedsize_t', but argument 5 has type 'size_t' [-Wformat]drivers/char/random.c: In function 'random_read':drivers/char/random.c:1141:3: warning: format '%zd' expects argument of type 'signedsize_t', but argument 5 has type 'int' [-Wformat]drivers/char/random.c:1145:3: warning: format '%zd' expects argument of type 'signedsize_t', but argument 5 has type 'int' [-Wformat]drivers/char/random.c:1145:3: warning: format '%zd' expects argument of type 'signedsize_t', but argument 6 has type 'size_t' [-Wformat]drivers/char/random.c: In function 'write_pool':drivers/char/random.c:1213:11: warning: comparison of distinct pointer types lacks a cast [enabled by default]
Quoted 4 lines
Quoted 1 line
Ah, I get it. %zd vs %zu. This?
With the patch, there are still errors (below). I think the reason of the warnings is, (
size_t* 8) makes it an (int) because the constant 8 is (int).
Sorry (size_t * 8) becomes (unsigned int) because (size_t) is (unsigned int).
And the problem is specific to mn10300/cris: (size_t * 8) is no longer (size_t), which triggers the gcc warnings discussed here.
Thanks,
Fengguang
Quoted 90 lines
CC
drivers/char/random.o
/c/wfg/linux/drivers/char/random.c: In function 'xfer_secondary_pool':
/c/wfg/linux/drivers/char/random.c:827:3: warning: format '%zu' expects argument of type 'size_t', but argument 7 has type 'unsigned int' [-Wformat] /c/wfg/linux/drivers/char/random.c: In function 'account':
/c/wfg/linux/drivers/char/random.c:859:2: warning: format '%zu' expects argument of type 'size_t', but argument 5 has type 'unsigned int' [-Wformat] /c/wfg/linux/drivers/char/random.c:881:2: warning: format '%zu' expects argument of type 'size_t', but argument 5 has type 'unsigned int' [-Wformat] /c/wfg/linux/drivers/char/random.c: In function 'random_read':
/c/wfg/linux/drivers/char/random.c:1141:3: warning: format '%zu' expects argument of type 'size_t', but argument 5 has type 'int' [-Wformat] /c/wfg/linux/drivers/char/random.c:1145:3: warning: format '%zu' expects argument of type 'size_t', but argument 5 has type 'int' [-Wformat] /c/wfg/linux/drivers/char/random.c:1145:3: warning: format '%zu' expects argument of type 'size_t', but argument 6 has type 'unsigned int' [-Wformat]And that behavior is depending on arch. Changing %zu to %u will make mn10300/parisc/i386 etc. archs compile cleanly, however
x86_64goes wrong like this:/c/wfg/linux/drivers/char/random.c:827:3: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 7 has type ‘size_t’ [-Wformat]
So in
x86_64, (size_t* 8) is still of typesize_t.Thanks,
Fengguang
---Quoted 68 lines
From: Andrew Morton <[email protected]>
Subject: random-fix-debug-format-strings-fixs/%zd/%zu/ for unsigned `size_t'
Cc Jiri Kosina <[email protected]>Cc Theodore Ts'o <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
drivers/char/random.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)diff -puN
drivers/char/random.c~random-fix-debug-format-strings-fixdrivers/char/random.cdrivers/char/random.c renamed from drivers/char/random.c~random-fix-debug-format-strings-fix +6
-6@@ -825,7 +825,7 @@ static void xfer_secondary_pool(struct e bytes =min_t (int, bytes,sizeof (tmp));DEBUG_ENT ("going to reseed %s with %d bits " -"(%zd of %d requested)\n" , +"(%zu of %d requested)\n" , r->name, bytes *8 , nbytes *8 , r->entropy_count); bytes = extract_entropy(r->pull, tmp, bytes,@@ -856,7 +856,7 @@ static size_t account(struct entropy_stospin_lock_irqsave (&r->lock, flags);BUG_ON (r->entropy_count > r->poolinfo->POOLBITS); -DEBUG_ENT ("trying to extract %zd bits from %s\n" , +DEBUG_ENT ("trying to extract %zu bits from %s\n" , nbytes *8 , r->name);/* Can we pull enough? */ @@ -878,7 +878,7 @@ static size_t account(struct entropy_sto } } -DEBUG_ENT ("debiting %zd entropy credits from %s%s\n" , +DEBUG_ENT ("debiting %zu entropy credits from %s%s\n" , nbytes *8 , r->name, r->limit ?"" :" (unlimited)" );spin_unlock_irqrestore (&r->lock, flags);@@ -1138,11 +1138,11 @@ random_read(struct file *file, char __usif (n >SEC_XFER_SIZE ) n =SEC_XFER_SIZE ; -DEBUG_ENT ("reading %zd bits\n" , n*8 ); +DEBUG_ENT ("reading %zu bits\n" , n*8 ); n =extract_entropy_user (&blocking_pool, buf, n); -DEBUG_ENT ("read got %zd bits (%zd still needed)\n" , +DEBUG_ENT ("read got %zu bits (%zu still needed)\n" , n*8 , (nbytes-n)*8 );if (n ==0 ) {@@ -1210,7 +1210,7 @@ write_pool(struct entropy_store *r, consconst char __user *p = buffer;while (count >0 ) { - bytes =min (count,sizeof (buf)); + bytes =min_t (size_t, count,sizeof (buf));if (copy_from_user (&buf, p, bytes))return -EFAULT ;_