docs: printk-formats: Fix hex printing of signed values
Subsystems (2)
Andy Shevchenko
reviewerPATCH 1/2 docs: printk-formats: Fix hex printing of signed values
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.
--- Documentation/core-api/printk-formats.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/core-api/printk-formats.rst +4 -4
@@ -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
Signature · 1 line
2.40.0.1.gaa8946217a0b
Andy Shevchenko
reviewerPATCH 2/2 docs: printk-formats: Treat char as always unsigned
The Linux kernel switched to have char be equivalent to usigned char. Reflect this in the printk specifiers.
--- Documentation/core-api/printk-formats.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/core-api/printk-formats.rst +2 -1
@@ -15,8 +15,9 @@ Integer types If variable is of Type, use printk format specifier: ------------------------------------------------------------ - char %d or %hhx + signed char %d or %hhx unsigned char %u or %x + char %u or %x short int %d or %hx unsigned short int %u or %x int %d or %x
Signature · 1 line
2.40.0.1.gaa8946217a0b
Re: [PATCH v1 2/2] docs: printk-formats: Treat char as always unsigned
Quoted 5 lines · Andy Shevchenko
The Linux kernel switched to have char be equivalent to usigned char. Reflect this in the printk specifiers.
Fixes 3bc753c06dd0 ("kbuild: treat char as always unsigned")Signed-off-by Andy Shevchenko <[email protected]>
Makes sense.
Best Regards,
Petr
PS: I am going to queue both patches for 6.6. They are not
urgent to be added in the -rc phase.
Andy Shevchenko
reviewerRe: [PATCH v1 2/2] docs: printk-formats: Treat char as always unsigned
Quoted 1 line · Petr Mladek
On Mon 2023-07-03 17:58:39, Andy Shevchenko wrote:
...
Quoted 1 line
Reviewed-by Petr Mladek <[email protected]>
Thank you for the review!
Quoted 2 lines
PS: I am going to queue both patches for 6.6. They are not
urgent to be added in the -rc phase.
Sure, works for me.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Petr Mladek
maintainerRe: [PATCH v1 2/2] docs: printk-formats: Treat char as always unsigned
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Petr Mladek
On Mon 2023-07-03 17:58:39, Andy Shevchenko wrote:
PS: I am going to queue both patches for 6.6. They are not
urgent to be added in the -rc phase.Sure, works for me.
JFYI, both patches have been pushed into printk/linux.git, branch for-6.6-vsprintf-doc.
Best Regards,
Petr
Andy Shevchenko
reviewerQuoted 5 lines · Andy Shevchenko
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
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 <[email protected]>
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.
Best Regards,
Petr