linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How do I printk <type> correctly?
@ 2008-10-23 11:41 Alexey Dobriyan
  2008-10-23 11:51 ` David John
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Alexey Dobriyan @ 2008-10-23 11:41 UTC (permalink / raw)
  To: linux-kernel

If variable is of Type	use	printk format specifier.
---------------------------------------------------------
		int			%d or %x
		unsigned int		%u or %x
		long			%ld ot %lx
		unsigned long		%lu or %lx
		long long		%lld or %llx
		unsigned long long	%llu or %llx
		size_t			%zu or %zx
		ssize_t			%zd or %zx

Raw pointer value SHOULD be printed with %p.

u64 SHOULD be printed with %llu/%llx, (unsigned long long):

	printk("%llu", (unsigned long long)u64_var);

s64 SHOULD be printed with %lld/%llx, (long long):

	printk("%lld", (long long)s64_var);

If type is dependent on config option (sector_t), use format specifier
of biggest type and explicitly cast to it.

Reminder: sizeof() result is of type size_t.

Thank you for your cooperation.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 11:41 How do I printk <type> correctly? Alexey Dobriyan
@ 2008-10-23 11:51 ` David John
  2008-10-23 12:06   ` Alexey Dobriyan
  2008-10-23 15:13 ` Johannes Berg
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: David John @ 2008-10-23 11:51 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel

Alexey Dobriyan wrote:
> If variable is of Type	use	printk format specifier.
> ---------------------------------------------------------
> 		int			%d or %x
> 		unsigned int		%u or %x
> 		long			%ld ot %lx
> 		unsigned long		%lu or %lx
> 		long long		%lld or %llx
> 		unsigned long long	%llu or %llx
> 		size_t			%zu or %zx
> 		ssize_t			%zd or %zx
> 
> Raw pointer value SHOULD be printed with %p.
> 
> u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> 
> 	printk("%llu", (unsigned long long)u64_var);
> 
> s64 SHOULD be printed with %lld/%llx, (long long):
> 
> 	printk("%lld", (long long)s64_var);
> 
> If type is dependent on config option (sector_t), use format specifier
> of biggest type and explicitly cast to it.
> 
> Reminder: sizeof() result is of type size_t.
> 
> Thank you for your cooperation.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

Useful list, but I think there are more format specifiers available with
printk though.

David.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 11:51 ` David John
@ 2008-10-23 12:06   ` Alexey Dobriyan
  0 siblings, 0 replies; 13+ messages in thread
From: Alexey Dobriyan @ 2008-10-23 12:06 UTC (permalink / raw)
  To: David John; +Cc: linux-kernel

On Thu, Oct 23, 2008 at 05:21:47PM +0530, David John wrote:
> Useful list, but I think there are more format specifiers available with
> printk though.

This list for not generating compile-time warnings, nothing more.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 11:41 How do I printk <type> correctly? Alexey Dobriyan
  2008-10-23 11:51 ` David John
@ 2008-10-23 15:13 ` Johannes Berg
  2008-10-23 20:40   ` David Miller
  2008-10-28 23:11 ` Randy Dunlap
  2008-11-05 18:23 ` Randy Dunlap
  3 siblings, 1 reply; 13+ messages in thread
From: Johannes Berg @ 2008-10-23 15:13 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 465 bytes --]


> u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> 
> 	printk("%llu", (unsigned long long)u64_var);
> 
> s64 SHOULD be printed with %lld/%llx, (long long):
> 
> 	printk("%lld", (long long)s64_var);

out of curiosity, why are there platforms that use an "unsigned long"
for u64? An "unsigned long long" is 64-bits too even on 64-bit
platforms, so why the difference? Are there any differences like
alignment on some platforms?

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 15:13 ` Johannes Berg
@ 2008-10-23 20:40   ` David Miller
  2008-10-24  8:41     ` Johannes Berg
  0 siblings, 1 reply; 13+ messages in thread
From: David Miller @ 2008-10-23 20:40 UTC (permalink / raw)
  To: johannes; +Cc: adobriyan, linux-kernel

From: Johannes Berg <johannes@sipsolutions.net>
Date: Thu, 23 Oct 2008 17:13:26 +0200

> > u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> > 
> > 	printk("%llu", (unsigned long long)u64_var);
> > 
> > s64 SHOULD be printed with %lld/%llx, (long long):
> > 
> > 	printk("%lld", (long long)s64_var);
> 
> out of curiosity, why are there platforms that use an "unsigned long"
> for u64?

Because that type is large enough.

> An "unsigned long long" is 64-bits too even on 64-bit platforms, so
> why the difference? Are there any differences like alignment on some
> platforms?

I invite you to go make that change and then try to fixup all the
resulting build warnings.  Some of us already made an attempt at
some point in the past. :-/

But it's just papering over the core problem, that we can't extend
gcc's automatic printf format type checking easily.

Even if we make u64 the same type everywhere, things like sector_t
and other types which do have to vary by architecture will need
to be casted.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 20:40   ` David Miller
@ 2008-10-24  8:41     ` Johannes Berg
  0 siblings, 0 replies; 13+ messages in thread
From: Johannes Berg @ 2008-10-24  8:41 UTC (permalink / raw)
  To: David Miller; +Cc: adobriyan, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 814 bytes --]

On Thu, 2008-10-23 at 13:40 -0700, David Miller wrote:

> > An "unsigned long long" is 64-bits too even on 64-bit platforms, so
> > why the difference? Are there any differences like alignment on some
> > platforms?
> 
> I invite you to go make that change and then try to fixup all the
> resulting build warnings.  Some of us already made an attempt at
> some point in the past. :-/

Heh, ok. I was just curious really. I think that answers it well
enough :)

> But it's just papering over the core problem, that we can't extend
> gcc's automatic printf format type checking easily.
> 
> Even if we make u64 the same type everywhere, things like sector_t
> and other types which do have to vary by architecture will need
> to be casted.

Indeed, it doesn't really help that much.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 11:41 How do I printk <type> correctly? Alexey Dobriyan
  2008-10-23 11:51 ` David John
  2008-10-23 15:13 ` Johannes Berg
@ 2008-10-28 23:11 ` Randy Dunlap
  2008-10-29  6:15   ` Artem Bityutskiy
  2008-10-29  8:00   ` Artem Bityutskiy
  2008-11-05 18:23 ` Randy Dunlap
  3 siblings, 2 replies; 13+ messages in thread
From: Randy Dunlap @ 2008-10-28 23:11 UTC (permalink / raw)
  To: Alexey Dobriyan, lkml; +Cc: ericvh, mfasheh, dedekind

On Thu, 23 Oct 2008 15:41:33 +0400 Alexey Dobriyan wrote:

> If variable is of Type	use	printk format specifier.
> ---------------------------------------------------------
> 		int			%d or %x
> 		unsigned int		%u or %x
> 		long			%ld ot %lx
> 		unsigned long		%lu or %lx
> 		long long		%lld or %llx
> 		unsigned long long	%llu or %llx
> 		size_t			%zu or %zx
> 		ssize_t			%zd or %zx
> 
> Raw pointer value SHOULD be printed with %p.
> 
> u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> 
> 	printk("%llu", (unsigned long long)u64_var);
> 
> s64 SHOULD be printed with %lld/%llx, (long long):
> 
> 	printk("%lld", (long long)s64_var);
> 
> If type is dependent on config option (sector_t), use format specifier
> of biggest type and explicitly cast to it.
> 
> Reminder: sizeof() result is of type size_t.
> 
> Thank you for your cooperation.
  and attention.


Building for Alpha (cross-build) finds over 125 printk format warnings:

net/9p/client.c:820: warning: format '%llx' expects type 'long long unsigned int', but argument 4 has type 'u64'
net/9p/client.c:820: warning: format '%llx' expects type 'long long unsigned int', but argument 5 has type 'u64'
net/9p/client.c:867: warning: format '%llx' expects type 'long long unsigned int', but argument 4 has type 'u64'
net/9p/client.c:867: warning: format '%llx' expects type 'long long unsigned int', but argument 5 has type 'u64'
net/9p/client.c:932: warning: format '%llx' expects type 'long long unsigned int', but argument 5 has type 'u64'
net/9p/client.c:932: warning: format '%llx' expects type 'long long unsigned int', but argument 6 has type 'u64'
net/9p/client.c:982: warning: format '%llx' expects type 'long long unsigned int', but argument 4 has type 'u64'
net/9p/client.c:982: warning: format '%llx' expects type 'long long unsigned int', but argument 5 has type 'u64'
net/9p/client.c:1025: warning: format '%llx' expects type 'long long unsigned int', but argument 4 has type 'u64'
net/9p/client.c:1025: warning: format '%llx' expects type 'long long unsigned int', but argument 5 has type 'u64'
net/9p/client.c:1227: warning: format '%llx' expects type 'long long unsigned int', but argument 7 has type 'u64'
net/9p/client.c:1227: warning: format '%llx' expects type 'long long unsigned int', but argument 12 has type 'u64'
net/9p/client.c:1227: warning: format '%llx' expects type 'long long unsigned int', but argument 8 has type 'u64'
net/9p/client.c:1227: warning: format '%llx' expects type 'long long unsigned int', but argument 13 has type 'u64'
net/9p/client.c:1252: warning: format '%llx' expects type 'long long unsigned int', but argument 7 has type 'u64'
net/9p/client.c:1252: warning: format '%llx' expects type 'long long unsigned int', but argument 12 has type 'u64'
net/9p/client.c:1252: warning: format '%llx' expects type 'long long unsigned int', but argument 8 has type 'u64'
net/9p/client.c:1252: warning: format '%llx' expects type 'long long unsigned int', but argument 13 has type 'u64'

fs/ext4/balloc.c:615: warning: format '%lld' expects type 'long long int', but argument 2 has type 's64'
fs/ext4/inode.c:1833: warning: format '%lld' expects type 'long long int', but argument 2 has type 's64'
fs/ext4/inode.c:1835: warning: format '%lld' expects type 'long long int', but argument 2 has type 's64'

net/mac80211/rc80211_minstrel_debugfs.c:98: warning: format '%8llu' expects type 'long long unsigned int', but argument 11 has type 'u64'
net/mac80211/rc80211_minstrel_debugfs.c:98: warning: format '%8llu' expects type 'long long unsigned int', but argument 12 has type 'u64'
net/mac80211/rc80211_minstrel_debugfs.c:98: warning: format '%8llu' expects type 'long long unsigned int', but argument 11 has type 'u64'
net/mac80211/rc80211_minstrel_debugfs.c:98: warning: format '%8llu' expects type 'long long unsigned int', but argument 12 has type 'u64'

fs/ocfs2/xattr.c:2400: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:2400: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:2400: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:2424: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:2424: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:2424: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:2443: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2443: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2443: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2779: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2779: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2779: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2942: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2942: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:2942: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3060: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3060: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3060: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3060: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3060: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3060: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3189: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3189: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3189: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3189: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3189: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3189: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3360: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3360: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3360: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3360: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3360: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3360: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3431: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3431: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3431: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3431: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3431: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3431: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3561: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3561: warning: format '%llu' expects type 'long long unsigned int', but argument 8 has type 'u64'
fs/ocfs2/xattr.c:3561: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3561: warning: format '%llu' expects type 'long long unsigned int', but argument 8 has type 'u64'
fs/ocfs2/xattr.c:3561: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3561: warning: format '%llu' expects type 'long long unsigned int', but argument 8 has type 'u64'
fs/ocfs2/xattr.c:3629: warning: format '%llu' expects type 'long long unsigned int', but argument 8 has type 'u64'
fs/ocfs2/xattr.c:3629: warning: format '%llu' expects type 'long long unsigned int', but argument 8 has type 'u64'
fs/ocfs2/xattr.c:3629: warning: format '%llu' expects type 'long long unsigned int', but argument 8 has type 'u64'
fs/ocfs2/xattr.c:3718: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3718: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3718: warning: format '%llu' expects type 'long long unsigned int', but argument 7 has type 'u64'
fs/ocfs2/xattr.c:3763: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3763: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'
fs/ocfs2/xattr.c:3763: warning: format '%llu' expects type 'long long unsigned int', but argument 6 has type 'u64'

fs/ubifs/journal.c:693: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/journal.c:1131: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/dir.c:163: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/tnc.c:2680: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/tnc.c:2700: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/replay.c:1066: warning: format '%lu' expects type 'long unsigned int', but argument 7 has type 'ino_t'
fs/ubifs/orphan.c:108: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:135: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:142: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:154: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:159: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:451: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:539: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:612: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:843: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/orphan.c:856: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/recovery.c:1438: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/recovery.c:1443: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/recovery.c:1475: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/recovery.c:1495: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:105: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:105: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:110: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:110: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:114: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:114: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:118: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:118: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
fs/ubifs/debug.c:1591: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1671: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1674: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/debug.c:1680: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1699: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/debug.c:1788: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/debug.c:1821: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/debug.c:1833: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/debug.c:1924: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1932: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1938: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1945: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1953: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1960: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1967: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1973: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1988: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
fs/ubifs/debug.c:1991: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
fs/ubifs/debug.c:2009: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'ino_t'

drivers/isdn/sc/shmem.c:57: warning: format '%d' expects type 'int', but argument 3 has type 'size_t'
drivers/net/mlx4/en_rx.c:289: warning: format '%llx' expects type 'long long unsigned int', but argument 4 has type 'dma_addr_t'
drivers/net/mlx4/en_netdev.c:1002: warning: format '%llx' expects type 'long long unsigned int', but argument 5 has type 'u64'


---
~Randy

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-28 23:11 ` Randy Dunlap
@ 2008-10-29  6:15   ` Artem Bityutskiy
  2008-10-29  8:00   ` Artem Bityutskiy
  1 sibling, 0 replies; 13+ messages in thread
From: Artem Bityutskiy @ 2008-10-29  6:15 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Alexey Dobriyan, lkml, ericvh, mfasheh

On Tue, 2008-10-28 at 16:11 -0700, Randy Dunlap wrote:
> fs/ubifs/journal.c:693: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/journal.c:1131: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/dir.c:163: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/tnc.c:2680: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/tnc.c:2700: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/replay.c:1066: warning: format '%lu' expects type 'long unsigned int', but argument 7 has type 'ino_t'
> fs/ubifs/orphan.c:108: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:135: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:142: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:154: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:159: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:451: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:539: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:612: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:843: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/orphan.c:856: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/recovery.c:1438: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/recovery.c:1443: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/recovery.c:1475: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/recovery.c:1495: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:105: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:105: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:110: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:110: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:114: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:114: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:118: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:118: warning: format '%lu' expects type 'long unsigned int', but argument 3 has type 'ino_t'
> fs/ubifs/debug.c:1591: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1671: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1674: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/debug.c:1680: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1699: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/debug.c:1788: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/debug.c:1821: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/debug.c:1833: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/debug.c:1924: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1932: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1938: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1945: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1953: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1960: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1967: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1973: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1988: warning: format '%lu' expects type 'long unsigned int', but argument 4 has type 'ino_t'
> fs/ubifs/debug.c:1991: warning: format '%lu' expects type 'long unsigned int', but argument 5 has type 'ino_t'
> fs/ubifs/debug.c:2009: warning: format '%lu' expects type 'long unsigned int', but argument 2 has type 'ino_t'

I'll look at these and fix, thank you!

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-28 23:11 ` Randy Dunlap
  2008-10-29  6:15   ` Artem Bityutskiy
@ 2008-10-29  8:00   ` Artem Bityutskiy
  2008-10-29 15:34     ` Randy Dunlap
  1 sibling, 1 reply; 13+ messages in thread
From: Artem Bityutskiy @ 2008-10-29  8:00 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Alexey Dobriyan, lkml, ericvh, mfasheh

On Tue, 2008-10-28 at 16:11 -0700, Randy Dunlap wrote:
> On Thu, 23 Oct 2008 15:41:33 +0400 Alexey Dobriyan wrote:
> 
> > If variable is of Type	use	printk format specifier.
> > ---------------------------------------------------------
> > 		int			%d or %x
> > 		unsigned int		%u or %x
> > 		long			%ld ot %lx
> > 		unsigned long		%lu or %lx
> > 		long long		%lld or %llx
> > 		unsigned long long	%llu or %llx
> > 		size_t			%zu or %zx
> > 		ssize_t			%zd or %zx
> > 
> > Raw pointer value SHOULD be printed with %p.
> > 
> > u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> > 
> > 	printk("%llu", (unsigned long long)u64_var);
> > 
> > s64 SHOULD be printed with %lld/%llx, (long long):
> > 
> > 	printk("%lld", (long long)s64_var);
> > 
> > If type is dependent on config option (sector_t), use format specifier
> > of biggest type and explicitly cast to it.
> > 
> > Reminder: sizeof() result is of type size_t.

Do we have this somewhere in Documentation? Would be nice to have it.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-29  8:00   ` Artem Bityutskiy
@ 2008-10-29 15:34     ` Randy Dunlap
  2008-10-29 15:36       ` Artem Bityutskiy
  0 siblings, 1 reply; 13+ messages in thread
From: Randy Dunlap @ 2008-10-29 15:34 UTC (permalink / raw)
  To: dedekind; +Cc: Alexey Dobriyan, lkml, ericvh, mfasheh

On Wed, 29 Oct 2008 10:00:04 +0200 Artem Bityutskiy wrote:

> On Tue, 2008-10-28 at 16:11 -0700, Randy Dunlap wrote:
> > On Thu, 23 Oct 2008 15:41:33 +0400 Alexey Dobriyan wrote:
> > 
> > > If variable is of Type	use	printk format specifier.
> > > ---------------------------------------------------------
> > > 		int			%d or %x
> > > 		unsigned int		%u or %x
> > > 		long			%ld ot %lx
> > > 		unsigned long		%lu or %lx
> > > 		long long		%lld or %llx
> > > 		unsigned long long	%llu or %llx
> > > 		size_t			%zu or %zx
> > > 		ssize_t			%zd or %zx
> > > 
> > > Raw pointer value SHOULD be printed with %p.
> > > 
> > > u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> > > 
> > > 	printk("%llu", (unsigned long long)u64_var);
> > > 
> > > s64 SHOULD be printed with %lld/%llx, (long long):
> > > 
> > > 	printk("%lld", (long long)s64_var);
> > > 
> > > If type is dependent on config option (sector_t), use format specifier
> > > of biggest type and explicitly cast to it.
> > > 
> > > Reminder: sizeof() result is of type size_t.
> 
> Do we have this somewhere in Documentation? Would be nice to have it.

It's in the C standard, which we don't try to put into Documentation/ AFAIK.

section 6.5.3.4, The sizeof operator:

4 The value of the result is implementation-defined, and its type (an unsigned integer type)
is size_t, defined in <stddef.h> (and other headers).


---
~Randy

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-29 15:34     ` Randy Dunlap
@ 2008-10-29 15:36       ` Artem Bityutskiy
  2008-10-29 15:43         ` Randy Dunlap
  0 siblings, 1 reply; 13+ messages in thread
From: Artem Bityutskiy @ 2008-10-29 15:36 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Alexey Dobriyan, lkml, ericvh, mfasheh

On Wed, 2008-10-29 at 08:34 -0700, Randy Dunlap wrote:
> It's in the C standard, which we don't try to put into Documentation/ AFAIK.
> 
> section 6.5.3.4, The sizeof operator:
> 
> 4 The value of the result is implementation-defined, and its type (an unsigned integer type)
> is size_t, defined in <stddef.h> (and other headers).

Well, OK. I was more thinking about printing stuff like ino_t.
UBIFS used %lu for this which was the source of warnings.

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-29 15:36       ` Artem Bityutskiy
@ 2008-10-29 15:43         ` Randy Dunlap
  0 siblings, 0 replies; 13+ messages in thread
From: Randy Dunlap @ 2008-10-29 15:43 UTC (permalink / raw)
  To: dedekind; +Cc: Alexey Dobriyan, lkml, ericvh, mfasheh

Artem Bityutskiy wrote:
> On Wed, 2008-10-29 at 08:34 -0700, Randy Dunlap wrote:
>> It's in the C standard, which we don't try to put into Documentation/ AFAIK.
>>
>> section 6.5.3.4, The sizeof operator:
>>
>> 4 The value of the result is implementation-defined, and its type (an unsigned integer type)
>> is size_t, defined in <stddef.h> (and other headers).
> 
> Well, OK. I was more thinking about printing stuff like ino_t.
> UBIFS used %lu for this which was the source of warnings.

I've been thinking of adding (trying to add) Alexey's hints in the
Doc/ tree in some new file.

-- 
~Randy

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How do I printk <type> correctly?
  2008-10-23 11:41 How do I printk <type> correctly? Alexey Dobriyan
                   ` (2 preceding siblings ...)
  2008-10-28 23:11 ` Randy Dunlap
@ 2008-11-05 18:23 ` Randy Dunlap
  3 siblings, 0 replies; 13+ messages in thread
From: Randy Dunlap @ 2008-11-05 18:23 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel

On Thu, 23 Oct 2008 15:41:33 +0400 Alexey Dobriyan wrote:

> If variable is of Type	use	printk format specifier.
> ---------------------------------------------------------
> 		int			%d or %x
> 		unsigned int		%u or %x
> 		long			%ld ot %lx
> 		unsigned long		%lu or %lx
> 		long long		%lld or %llx
> 		unsigned long long	%llu or %llx
> 		size_t			%zu or %zx
> 		ssize_t			%zd or %zx

Add, or is this one too infrequent to be listed here?

		tcflag_t		%lu or %lx or %lo

Since tcflag_t is unsigned int (on most $ARCH-es) or unsigned long (on sparc32),
use a cast to (unsigned long)flag when printing it.

[Yes, a sparc32 build gets lots of printk format warnings when printing tcflag_t
values.]


> Raw pointer value SHOULD be printed with %p.
> 
> u64 SHOULD be printed with %llu/%llx, (unsigned long long):
> 
> 	printk("%llu", (unsigned long long)u64_var);
> 
> s64 SHOULD be printed with %lld/%llx, (long long):
> 
> 	printk("%lld", (long long)s64_var);
> 
> If type is dependent on config option (sector_t), use format specifier
> of biggest type and explicitly cast to it.
> 
> Reminder: sizeof() result is of type size_t.
> 
> Thank you for your cooperation.
> --

---
~Randy

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-11-05 18:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-23 11:41 How do I printk <type> correctly? Alexey Dobriyan
2008-10-23 11:51 ` David John
2008-10-23 12:06   ` Alexey Dobriyan
2008-10-23 15:13 ` Johannes Berg
2008-10-23 20:40   ` David Miller
2008-10-24  8:41     ` Johannes Berg
2008-10-28 23:11 ` Randy Dunlap
2008-10-29  6:15   ` Artem Bityutskiy
2008-10-29  8:00   ` Artem Bityutskiy
2008-10-29 15:34     ` Randy Dunlap
2008-10-29 15:36       ` Artem Bityutskiy
2008-10-29 15:43         ` Randy Dunlap
2008-11-05 18:23 ` Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).