Skip to contentSkip to conversation

docs: add extra integer types to printk-formats

PATCH In review Louis Taylor 7 participants 10 messages Mar 3, 2019 – Mar 5, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs: add extra integer types to printk-formats

A few commonly used integer types were absent from this table, so add them.

---
 Documentation/core-api/printk-formats.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/core-api/printk-formats.rst +8 -0
index a7fae4538946..6f08b1b6240a 100644
@@ -19,8 +19,16 @@ Integer types
 		unsigned long		%lu or %lx
 		long long		%lld or %llx
 		unsigned long long	%llu or %llx
+		short int		%hd or %hx
+		unsigned short int	%hu or %hx
+		char			%hhd or %hhx
+		unsigned char		%hhu or %hhx
 		size_t			%zu or %zx
 		ssize_t			%zd or %zx
+		s8			%hhd or %hhx
+		u8			%hhu or %hhx
+		s16			%hd or %hx
+		u16			%hu or %hx
 		s32			%d or %x
 		u32			%u or %x
 		s64			%lld or %llx
Signature · 1 line
2.20.1
#1 lore raw
Quoted 2 lines · Louis Taylor

A few commonly used integer types were absent from this table, so add them.

I'm not against the patch, but isn't obvious by reading POSIX and / or man printf(3)?

Quoted 1 line

Thanks for the link.

It's interesting to see how compiler type mindset applies to fixing drivers and hardware related code...

Quoted 30 lines
---
 Documentation/core-api/printk-formats.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/core-api/printk-formats.rst +8 -0
index a7fae4538946..6f08b1b6240a 100644
@@ -19,8 +19,16 @@ Integer types
 		unsigned long		%lu or %lx
 		long long		%lld or %llx
 		unsigned long long	%llu or %llx
+		short int		%hd or %hx
+		unsigned short int	%hu or %hx
+		char			%hhd or %hhx
+		unsigned char		%hhu or %hhx
 		size_t			%zu or %zx
 		ssize_t			%zd or %zx
+		s8			%hhd or %hhx
+		u8			%hhu or %hhx
+		s16			%hd or %hx
+		u16			%hu or %hx
 		s32			%d or %x
 		u32			%u or %x
 		s64			%lld or %llx
Signature · 1 line
2.20.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Louis Taylor

A few commonly used integer types were absent from this table, so add them.

I'm not against the patch, but isn't obvious by reading POSIX and / or man printf(3)?

You'd think; but based on the sheer number of -Wformat warnings (~450), I'm not so sure. At least with this patch they're "above the fold."

The kernel also has its own format flag extensions, and does not implement %n (for good reason), so it's better to be explicit than imply posix or glibc compat.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
Quoted 11 lines · Nick Desaulniers
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Louis Taylor

A few commonly used integer types were absent from this table, so add them.

I'm not against the patch, but isn't obvious by reading POSIX and / or man printf(3)?

You'd think; but based on the sheer number of -Wformat warnings (~450), I'm not so sure.

<shrug> software defects are always present.

Many of the -Wformat warnings are bogus too.

There's nothing wrong with using %x for a unsigned int of less than long size. (u8/u16)

Quoted 2 lines

At least with this patch they're "above the
fold."

I'd personally go with
"posix plus kernel specific deletions and extensions"

Quoted 3 lines

The kernel also has its own format flag extensions, and does not implement %n (for good reason), so it's better to be explicit than imply posix or glibc compat.

%i is also supported and used a few hundred times

#4 lore raw
Quoted 4 lines · Joe Perches

Many of the -Wformat warnings are bogus too.

There's nothing wrong with using %x for a unsigned int of less than long size. (u8/u16)

I believe you to be incorrect.

6.5.2.2 Function calls

7 If the expression that denotes the called function has a type that does
include a prototype, the arguments are implicitly converted, as if by assignment, to the types of the corresponding parameters, taking the type of each parameter to be the unqualified version of its declared type. The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.

I could define a calling convention for my CPU which says to pack u8s and u16s as tightly as possible in registers (or on the stack), rather than the prevailing calling convention of having each argument take up at least one register-sized slot.

#5 lore raw
Quoted 7 lines · Matthew Wilcox
Quoted 4 lines · Joe Perches

Many of the -Wformat warnings are bogus too.

There's nothing wrong with using %x for a unsigned int of less than long size. (u8/u16)

I believe you to be incorrect.

No, you're right, I got tangled up in the spec language and stopped reading too soon.

Quoted 9 lines

6.5.2.2 Function calls

7 If the expression that denotes the called function has a type that does
include a prototype, the arguments are implicitly converted, as if by assignment, to the types of the corresponding parameters, taking the type of each parameter to be the unqualified version of its declared type. The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.

... the default argument promotions performed on the trailing arguments promote short/char to int. So you were right.

Quoted 4 lines

I could define a calling convention for my CPU which says to pack u8s and u16s as tightly as possible in registers (or on the stack), rather than the prevailing calling convention of having each argument take up at least one register-sized slot.

... and that is just wrong; it's not allowed.

#6 lore raw
In reply to Matthew Wilcox
Quoted 10 lines · Matthew Wilcox
Quoted 4 lines · Joe Perches

Many of the -Wformat warnings are bogus too.

There's nothing wrong with using %x for a unsigned int of less than long size. (u8/u16)

I believe you to be incorrect.

6.5.2.2 Function calls

Quoted 7 lines

7 If the expression that denotes the called function has a type that does
include a prototype, the arguments are implicitly converted, as if by assignment, to the types of the corresponding parameters, taking the type of each parameter to be the unqualified version of its declared type. The ellipsis notation in a function prototype declarator causes argument type conversion to stop after the last declared parameter. The default argument promotions are performed on trailing arguments.

Look at default argument promotions for varargs functions. (integer promotions)

Quoted 4 lines

I could define a calling convention for my CPU which says to pack u8s and u16s as tightly as possible in registers (or on the stack), rather than the prevailing calling convention of having each argument take up at least one register-sized slot.

Doesn't matter for varargs. See above.

cheers, Joe

reviewer
#7 lore raw
In reply to Joe Perches
Quoted 17 lines · Joe Perches
Quoted 11 lines · Nick Desaulniers
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Louis Taylor

A few commonly used integer types were absent from this table, so add them.

I'm not against the patch, but isn't obvious by reading POSIX and / or man printf(3)?

You'd think; but based on the sheer number of -Wformat warnings (~450), I'm not so sure.

<shrug> software defects are always present.

Many of the -Wformat warnings are bogus too.

Quoted 8 lines

There's nothing wrong with using %x for a unsigned int of less than long size. (u8/u16)

Quoted 2 lines

At least with this patch they're "above the
fold."

I'd personally go with
"posix plus kernel specific deletions and extensions"

Yeah, I don't think that all of the "standard" types/formats need to be in there. Just the differences.

Quoted 7 lines
Quoted 3 lines

The kernel also has its own format flag extensions, and does not implement %n (for good reason), so it's better to be explicit than imply posix or glibc compat.

%i is also supported and used a few hundred times

Signature · 1 line
~Randy
maintainer
#8 lore raw
In reply to Louis Taylor
Quoted 15 lines · Louis Taylor

A few commonly used integer types were absent from this table, so add them.

---
 Documentation/core-api/printk-formats.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/core-api/printk-formats.rst +0 -0
index a7fae4538946..6f08b1b6240a 100644

Documentation/core-api/printk-formats.rst Integer types · line 25

Quoted 7 lines
Documentation/core-api/printk-formats.rst +4 -0
@@ -19,8 +19,16 @@ Integer types
 		unsigned long		%lu or %lx
 		long long		%lld or %llx
 		unsigned long long	%llu or %llx
+		short int		%hd or %hx
+		unsigned short int	%hu or %hx
+		char			%hhd or %hhx
+		unsigned char		%hhu or %hhx

These should get moved to the beginning of the table to have all variants sorted by size.

Documentation/core-api/printk-formats.rst Integer types · line 34

Quoted 9 lines
Documentation/core-api/printk-formats.rst +4 -0
 		size_t			%zu or %zx
 		ssize_t			%zd or %zx
+		s8			%hhd or %hhx
+		u8			%hhu or %hhx
+		s16			%hd or %hx
+		u16			%hu or %hx
 		s32			%d or %x
 		u32			%u or %x
 		s64			%lld or %llx

Let's get it in when people are doing the clean up.

I have fixed the sorting and committed into printk.git, branch for-5.1, see
https://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk.git/commit/?h=for-5.1&id=943ca6ad81e5b37bd5d22cbab5ad06dc97fc001c

Best Regards,
Petr

Reviewed-by
#9 lore raw
Quoted 38 lines · Petr Mladek
Quoted 15 lines · Louis Taylor

A few commonly used integer types were absent from this table, so add them.

---
 Documentation/core-api/printk-formats.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/core-api/printk-formats.rst +0 -0
index a7fae4538946..6f08b1b6240a 100644

Documentation/core-api/printk-formats.rst Integer types · line 25

Quoted 7 lines
Documentation/core-api/printk-formats.rst +4 -0
@@ -19,8 +19,16 @@ Integer types
              unsigned long           %lu or %lx
              long long               %lld or %llx
              unsigned long long      %llu or %llx
+             short int               %hd or %hx
+             unsigned short int      %hu or %hx
+             char                    %hhd or %hhx
+             unsigned char           %hhu or %hhx

These should get moved to the beginning of the table to have all variants sorted by size.

Documentation/core-api/printk-formats.rst Integer types · line 34

Quoted 9 lines
Documentation/core-api/printk-formats.rst +4 -0
              size_t                  %zu or %zx
              ssize_t                 %zd or %zx
+             s8                      %hhd or %hhx
+             u8                      %hhu or %hhx
+             s16                     %hd or %hx
+             u16                     %hu or %hx
              s32                     %d or %x
              u32                     %u or %x
              s64                     %lld or %llx
Quoted 5 lines

Let's get it in when people are doing the clean up.

I have fixed the sorting and committed into printk.git, branch for-5.1, see
https://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk.git/commit/?h=for-5.1&id=943ca6ad81e5b37bd5d22cbab5ad06dc97fc001c

Sure that's fine. Thanks for keeping Louis as the author, and for the clean up.

Signature · 2 lines
Thanks,
~Nick Desaulniers