linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]
@ 2019-09-06 21:11 Joe Perches
  2019-09-06 21:37 ` Louis Taylor
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Joe Perches @ 2019-09-06 21:11 UTC (permalink / raw)
  To: Jonathan Corbet; +Cc: linux-doc, linux-kernel, Louis Taylor

Standard integer promotion is already done and %hx and %hhx is useless
so do not encourage the use of %hh[xudi] or %h[xudi].

As Linus said in:
Link: https://lore.kernel.org/lkml/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/

It's a pointless warning, making for more complex code, and
making people remember esoteric printf format details that have no
reason for existing.

The "h" and "hh" things should never be used. The only reason for them
being used if if you have an "int", but you want to print it out as a
"char" (and honestly, that is a really bad reason, you'd be better off
just using a proper cast to make the code more obvious).

So if what you have a "char" (or unsigned char) you should always just
print it out as an "int", knowing that the compiler already did the
proper type conversion.

Signed-off-by: Joe Perches <joe@perches.com>
---
 Documentation/core-api/printk-formats.rst | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index c6224d039bcb..ecbebf4ca8e7 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -13,10 +13,10 @@ Integer types
 
 	If variable is of Type,		use printk format specifier:
 	------------------------------------------------------------
-		char			%hhd or %hhx
-		unsigned char		%hhu or %hhx
-		short int		%hd or %hx
-		unsigned short int	%hu or %hx
+		char			%d or %x
+		unsigned char		%u or %x
+		short int		%d or %x
+		unsigned short int	%u or %x
 		int			%d or %x
 		unsigned int		%u or %x
 		long			%ld or %lx
@@ -25,10 +25,10 @@ Integer types
 		unsigned long long	%llu or %llx
 		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
+		s8			%d or %x
+		u8			%u or %x
+		s16			%d or %x
+		u16			%u or %x
 		s32			%d or %x
 		u32			%u or %x
 		s64			%lld or %llx



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

* Re: [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]
  2019-09-06 21:11 [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi] Joe Perches
@ 2019-09-06 21:37 ` Louis Taylor
  2019-09-07 20:23 ` Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Louis Taylor @ 2019-09-06 21:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-doc, corbet, linux-kernel

On Fri, Sep 06, 2019 at 02:11:51PM -0700, Joe Perches wrote:
> Standard integer promotion is already done and %hx and %hhx is useless
> so do not encourage the use of %hh[xudi] or %h[xudi].
> 
> As Linus said in:
> Link: https://lore.kernel.org/lkml/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/
> 
> It's a pointless warning, making for more complex code, and
> making people remember esoteric printf format details that have no
> reason for existing.
> 
> The "h" and "hh" things should never be used. The only reason for them
> being used if if you have an "int", but you want to print it out as a
> "char" (and honestly, that is a really bad reason, you'd be better off
> just using a proper cast to make the code more obvious).
> 
> So if what you have a "char" (or unsigned char) you should always just
> print it out as an "int", knowing that the compiler already did the
> proper type conversion.

Yeah, makes sense. Sorry for adding these in the first place.

Reviewed-by: Louis Taylor <louis@kragniz.eu>

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

* Re: [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]
  2019-09-06 21:11 [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi] Joe Perches
  2019-09-06 21:37 ` Louis Taylor
@ 2019-09-07 20:23 ` Andy Shevchenko
  2019-09-09  9:36 ` Jani Nikula
  2019-09-14  7:58 ` Jonathan Corbet
  3 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2019-09-07 20:23 UTC (permalink / raw)
  To: Joe Perches
  Cc: Jonathan Corbet, Linux Documentation List, linux-kernel, Louis Taylor

On Sat, Sep 7, 2019 at 9:15 PM Joe Perches <joe@perches.com> wrote:
>
> Standard integer promotion is already done and %hx and %hhx is useless
> so do not encourage the use of %hh[xudi] or %h[xudi].
>
> As Linus said in:
> Link: https://lore.kernel.org/lkml/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/
>
> It's a pointless warning, making for more complex code, and
> making people remember esoteric printf format details that have no
> reason for existing.
>
> The "h" and "hh" things should never be used. The only reason for them
> being used if if you have an "int", but you want to print it out as a
> "char" (and honestly, that is a really bad reason, you'd be better off
> just using a proper cast to make the code more obvious).
>
> So if what you have a "char" (or unsigned char) you should always just
> print it out as an "int", knowing that the compiler already did the
> proper type conversion.

> -               char                    %hhd or %hhx
> -               short int               %hd or %hx
> +               char                    %d or %x
> +               short int               %d or %x

> +               s8                      %d or %x
> +               s16                     %d or %x

This is incorrect. Integral promotions promotes also sign, which will
produce too many f:s.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]
  2019-09-06 21:11 [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi] Joe Perches
  2019-09-06 21:37 ` Louis Taylor
  2019-09-07 20:23 ` Andy Shevchenko
@ 2019-09-09  9:36 ` Jani Nikula
  2019-09-14  7:58 ` Jonathan Corbet
  3 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2019-09-09  9:36 UTC (permalink / raw)
  To: Joe Perches, Jonathan Corbet; +Cc: linux-doc, linux-kernel, Louis Taylor

On Fri, 06 Sep 2019, Joe Perches <joe@perches.com> wrote:
> Link: https://lore.kernel.org/lkml/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/

I thought Link: was for referencing the patch on the mailing list that
became the commit in git.

BR,
Jani.

-- 
Jani Nikula, Intel Open Source Graphics Center

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

* Re: [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]
  2019-09-06 21:11 [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi] Joe Perches
                   ` (2 preceding siblings ...)
  2019-09-09  9:36 ` Jani Nikula
@ 2019-09-14  7:58 ` Jonathan Corbet
  3 siblings, 0 replies; 5+ messages in thread
From: Jonathan Corbet @ 2019-09-14  7:58 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-doc, linux-kernel, Louis Taylor

On Fri, 06 Sep 2019 14:11:51 -0700
Joe Perches <joe@perches.com> wrote:

> Standard integer promotion is already done and %hx and %hhx is useless
> so do not encourage the use of %hh[xudi] or %h[xudi].
> 
> As Linus said in:
> Link: https://lore.kernel.org/lkml/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/
> 
> It's a pointless warning, making for more complex code, and
> making people remember esoteric printf format details that have no
> reason for existing.
> 
> The "h" and "hh" things should never be used. The only reason for them
> being used if if you have an "int", but you want to print it out as a
> "char" (and honestly, that is a really bad reason, you'd be better off
> just using a proper cast to make the code more obvious).
> 
> So if what you have a "char" (or unsigned char) you should always just
> print it out as an "int", knowing that the compiler already did the
> proper type conversion.
> 
> Signed-off-by: Joe Perches <joe@perches.com>

Applied, thanks.

I took the liberty of removing "Link:" (but not the URL) from the commit
message.  That wasn't a patch tag, there is no real reason to make it
look like one...

jon

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

end of thread, other threads:[~2019-09-14  7:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 21:11 [PATCH] docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi] Joe Perches
2019-09-06 21:37 ` Louis Taylor
2019-09-07 20:23 ` Andy Shevchenko
2019-09-09  9:36 ` Jani Nikula
2019-09-14  7:58 ` Jonathan Corbet

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).