[v1,1/2] docs: printk-formats: Fix hex printing of signed values

Message ID 20230703145839.14248-1-andriy.shevchenko@linux.intel.com
State New
Headers
Series [v1,1/2] docs: printk-formats: Fix hex printing of signed values |

Commit Message

Andy Shevchenko July 3, 2023, 2:58 p.m. UTC
  The commit cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of
unnecessary %h[xudi] and %hh[xudi]") obviously missed the point of sign
promotion for the signed values lesser than int. In such case %x prints
not the same as %h[h]x. Restore back those specifiers for the signed hex
cases.

Fixes: cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 Documentation/core-api/printk-formats.rst | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Andy Shevchenko July 3, 2023, 3:08 p.m. UTC | #1
On Mon, Jul 03, 2023 at 05:58:38PM +0300, Andy Shevchenko wrote:
> The commit cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of
> unnecessary %h[xudi] and %hh[xudi]") obviously missed the point of sign
> promotion for the signed values lesser than int. In such case %x prints
> not the same as %h[h]x. Restore back those specifiers for the signed hex
> cases.

FWIW, currently we luckily have only one ABI case
drivers/power/supply/bq24190_charger.c:466
which luckily uses unsigned value for that specifier.

The rest is debug and error messages along with tracepoints.
The tracepoints might have an undesired, but not critical,
deviation. Nevertheless, promoting sign for hex values seems
to me the wrong suggestion.
  
Petr Mladek July 14, 2023, 3:32 p.m. UTC | #2
On Mon 2023-07-03 17:58:38, Andy Shevchenko wrote:
> The commit cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of
> unnecessary %h[xudi] and %hh[xudi]") obviously missed the point of sign
> promotion for the signed values lesser than int. In such case %x prints
> not the same as %h[h]x. Restore back those specifiers for the signed hex
> cases.
> 
> Fixes: cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Makes sense. %d would print the same (small) negative number even when
casted do int. But %x would always add more "ff"s up to 4 bytes.

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr
  

Patch

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index dfe7e75a71de..2f3a6e0b3fc4 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -15,9 +15,9 @@  Integer types
 
 	If variable is of Type,		use printk format specifier:
 	------------------------------------------------------------
-		char			%d or %x
+		char			%d or %hhx
 		unsigned char		%u or %x
-		short int		%d or %x
+		short int		%d or %hx
 		unsigned short int	%u or %x
 		int			%d or %x
 		unsigned int		%u or %x
@@ -27,9 +27,9 @@  Integer types
 		unsigned long long	%llu or %llx
 		size_t			%zu or %zx
 		ssize_t			%zd or %zx
-		s8			%d or %x
+		s8			%d or %hhx
 		u8			%u or %x
-		s16			%d or %x
+		s16			%d or %hx
 		u16			%u or %x
 		s32			%d or %x
 		u32			%u or %x