vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering
Subsystems (4)
Petr Mladek
maintainerPATCH 1/1 vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example, it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)
But people expect that the ordering stays the same. The network ordering is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect the output ordering of IPv4 addresses while they affect the reading order in case of FourCC code.
Avoid the confusion by replacing the "n" modifier with "hR", aka reverse host ordering. It is inspired by the existing %p[mM]R printf format.
---
Hi,
I am sending this as a proper patch. It would be nice to queue it together with the other patches adding the generic printf modifiers.
Best Regards,
Petr
---Documentation/core-api/printk-formats.rst | 10 +++++-----
lib/tests/printf_kunit.c | 4 ++-- lib/vsprintf.c | 11 ++++++++--- 3 files changed, 15 insertions(+), 10 deletions(-)
Documentation/core-api/printk-formats.rst +5 -5
@@ -652,7 +652,7 @@ Generic FourCC code ------------------- :: - %p4c[hnlb] gP00 (0x67503030) + %p4c[h[R]lb] gP00 (0x67503030) Print a generic FourCC code, as both ASCII characters and its numerical value as hexadecimal.
@@ -660,23 +660,23 @@ value as hexadecimal. The generic FourCC code is always printed in the big-endian format, the most significant byte first. This is the opposite of V4L/DRM FourCCs. -The additional ``h``, ``n``, ``l``, and ``b`` specifiers define what +The additional ``h``, ``hR``, ``l``, and ``b`` specifiers define what endianness is used to load the stored bytes. The data might be interpreted -using the host byte order, network byte order, little-endian, or big-endian. +using the host, reversed host byte order, little-endian, or big-endian. Passed by reference. Examples for a little-endian machine, given &(u32)0x67503030:: %p4ch gP00 (0x67503030) - %p4cn 00Pg (0x30305067) + %p4chR 00Pg (0x30305067) %p4cl gP00 (0x67503030) %p4cb 00Pg (0x30305067) Examples for a big-endian machine, given &(u32)0x67503030:: %p4ch gP00 (0x67503030) - %p4cn 00Pg (0x30305067) + %p4chR 00Pg (0x30305067) %p4cl 00Pg (0x30305067) %p4cb gP00 (0x67503030)
lib/tests/printf_kunit.c +2 -2
@@ -726,7 +726,7 @@ static void fourcc_pointer(struct kunit *kunittest)static const struct fourcc_struct try_ch[] = { {0x41424344 ,"ABCD (0x41424344)" , }, }; -static const struct fourcc_struct try_cn[] = { +static const struct fourcc_struct try_chR[] = { {0x41424344 ,"DCBA (0x44434241)" , }, };static const struct fourcc_struct try_cl[] = {
@@ -738,7 +738,7 @@ static void fourcc_pointer(struct kunit *kunittest)fourcc_pointer_test (kunittest, try_cc,ARRAY_SIZE (try_cc),"%p4cc" );fourcc_pointer_test (kunittest, try_ch,ARRAY_SIZE (try_ch),"%p4ch" ); -fourcc_pointer_test (kunittest, try_cn,ARRAY_SIZE (try_cn),"%p4cn" ); +fourcc_pointer_test (kunittest, try_chR,ARRAY_SIZE (try_chR),"%p4chR" );fourcc_pointer_test (kunittest, try_cl,ARRAY_SIZE (try_cl),"%p4cl" );fourcc_pointer_test (kunittest, try_cb,ARRAY_SIZE (try_cb),"%p4cb" ); }
lib/vsprintf.c +8 -3
@@ -1804,9 +1804,8 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, orig =get_unaligned (fourcc);switch (fmt[2 ]) {case 'h' : -break ; -case 'n' : - orig =swab32 (orig); +if (fmt[3 ] =='R' ) + orig =swab32 (orig);break ;case 'l' : orig = (__force u32 )cpu_to_le32 (orig);
@@ -2396,6 +2395,12 @@ early_param("no_hash_pointers", no_hash_pointers_enable);* read the documentation (path below) first. * - 'NF' For a netdev_features_t * - '4cc' V4L2 or DRM FourCC code, with endianness and raw numerical value. +* - '4c[h[R]lb]' For generic FourCC code with raw numerical value. Both are +* displayed in the big-endian format. This is the opposite of V4L2 or +* DRM FourCCs. +* The additional specifiers define what endianness is used to load +* the stored bytes. The data might be interpreted using the host, +* reversed host byte order, little-endian, or big-endian. * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with * a certain separator (' ' by default): * C colon
Signature · 1 line
2.49.0
Quoted 20 lines · Petr Mladek
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example, it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)But people expect that the ordering stays the same. The network ordering is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect the output ordering of IPv4 addresses while they affect the reading order in case of FourCC code.
Quoted 7 lines
Avoid the confusion by replacing the "n" modifier with "hR", aka reverse host ordering. It is inspired by the existing %p[mM]R printf format.
Quoted 5 lines
---
Hi,I am sending this as a proper patch. It would be nice to queue it together with the other patches adding the generic printf modifiers.
Quoted 20 lines · Petr Mladek
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example, it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)But people expect that the ordering stays the same. The network ordering is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect the output ordering of IPv4 addresses while they affect the reading order in case of FourCC code.
Quoted 7 lines
Avoid the confusion by replacing the "n" modifier with "hR", aka reverse host ordering. It is inspired by the existing %p[mM]R printf format.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Since the other patches went thru drm-misc-next, I guess this should too?
Quoted 136 lines · Petr Mladek
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example, it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)But people expect that the ordering stays the same. The network ordering is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect the output ordering of IPv4 addresses while they affect the reading order in case of FourCC code.
Avoid the confusion by replacing the "n" modifier with "hR", aka reverse host ordering. It is inspired by the existing %p[mM]R printf format.
Reported-by Geert Uytterhoeven <[email protected]>Closes https://lore.kernel.org/r/CAMuHMdV9tX=TG7E_CrSF=2PY206tXf+_yYRuacG48EWEtJLo-Q@mail.gmail.com open hereSigned-off-by Petr Mladek <[email protected]>---
Hi,I am sending this as a proper patch. It would be nice to queue it together with the other patches adding the generic printf modifiers.
Best Regards,
Petr
---Documentation/core-api/printk-formats.rst| 10 +++++-----lib/tests/printf_kunit.c | 4 ++-- lib/vsprintf.c | 11 ++++++++--- 3 files changed, 15 insertions(+), 10 deletions(-)Documentation/core-api/printk-formats.rst +5
-5@@ -652,7 +652,7 @@ Generic FourCC code ------------------- :: - %p4c[hnlb] gP00 (0x67503030) + %p4c[h[R]lb] gP00 (0x67503030) Print a generic FourCC code, as both ASCII characters and its numerical value as hexadecimal.@@ -660,23 +660,23 @@ value as hexadecimal. The generic FourCC code is always printed in the big-endian format, the most significant byte first. This is the opposite of V4L/DRM FourCCs. -The additional ``h``, ``n``, ``l``, and ``b`` specifiers define what +The additional ``h``, ``hR``, ``l``, and ``b`` specifiers define what endianness is used to load the stored bytes. The data might be interpreted -using the host byte order, network byte order, little-endian, or big-endian. +using the host, reversed host byte order, little-endian, or big-endian. Passed by reference. Examples for a little-endian machine, given &(u32)0x67503030:: %p4ch gP00 (0x67503030) - %p4cn 00Pg (0x30305067) + %p4chR 00Pg (0x30305067) %p4cl gP00 (0x67503030) %p4cb 00Pg (0x30305067) Examples for a big-endian machine, given &(u32)0x67503030:: %p4ch gP00 (0x67503030) - %p4cn 00Pg (0x30305067) + %p4chR 00Pg (0x30305067) %p4cl 00Pg (0x30305067) %p4cb gP00 (0x67503030)lib/tests/printf_kunit.c +2
-2@@ -726,7 +726,7 @@ static void fourcc_pointer(struct kunit *kunittest)static const struct fourcc_struct try_ch[] = { {0x41424344 ,"ABCD (0x41424344)" , }, }; -static const struct fourcc_struct try_cn[] = { +static const struct fourcc_struct try_chR[] = { {0x41424344 ,"DCBA (0x44434241)" , }, };static const struct fourcc_struct try_cl[] = {@@ -738,7 +738,7 @@ static void fourcc_pointer(struct kunit *kunittest)fourcc_pointer_test (kunittest, try_cc,ARRAY_SIZE (try_cc),"%p4cc" );fourcc_pointer_test (kunittest, try_ch,ARRAY_SIZE (try_ch),"%p4ch" ); -fourcc_pointer_test (kunittest, try_cn,ARRAY_SIZE (try_cn),"%p4cn" ); +fourcc_pointer_test (kunittest, try_chR,ARRAY_SIZE (try_chR),"%p4chR" );fourcc_pointer_test (kunittest, try_cl,ARRAY_SIZE (try_cl),"%p4cl" );fourcc_pointer_test (kunittest, try_cb,ARRAY_SIZE (try_cb),"%p4cb" ); }lib/vsprintf.c +8
-3@@ -1804,9 +1804,8 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, orig =get_unaligned (fourcc);switch (fmt[2 ]) {case 'h' : -break ; -case 'n' : - orig =swab32 (orig); +if (fmt[3 ] =='R' ) + orig =swab32 (orig);break ;case 'l' : orig = (__force u32 )cpu_to_le32 (orig);@@ -2396,6 +2395,12 @@ early_param("no_hash_pointers", no_hash_pointers_enable);* read the documentation (path below) first. * - 'NF' For a netdev_features_t * - '4cc' V4L2 or DRM FourCC code, with endianness and raw numerical value. +* - '4c[h[R]lb]' For generic FourCC code with raw numerical value. Both are +* displayed in the big-endian format. This is the opposite of V4L2 or +* DRM FourCCs. +* The additional specifiers define what endianness is used to load +* the stored bytes. The data might be interpreted using the host, +* reversed host byte order, little-endian, or big-endian. * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with * a certain separator (' ' by default): * C colon Signature · 1 line
2.49.0
Quoted 4 lines · Alyssa Rosenzweig
Since the other patches went thru drm-misc-next, I guess this should too?
I think yes.
Quoted 27 lines · Petr Mladek
Quoted 24 lines
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example, it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)But people expect that the ordering stays the same. The network ordering is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect the output ordering of IPv4 addresses while they affect the reading order in case of FourCC code.
Avoid the confusion by replacing the "n" modifier with "hR", aka reverse host ordering. It is inspired by the existing %p[mM]R printf format.
Quoted 8 lines
Quoted 8 lines
Reported-by Geert Uytterhoeven <[email protected]>Closes https://lore.kernel.org/r/CAMuHMdV9tX=TG7E_CrSF=2PY206tXf+_yYRuacG48EWEtJLo-Q@mail.gmail.com open hereSigned-off-by Petr Mladek <[email protected]>---
Hi,I am sending this as a proper patch. It would be nice to queue it together with the other patches adding the generic printf modifiers.
Atleast thats what this says.
Petr Mladek
maintainerQuoted 9 lines · Aditya Garg
Quoted 4 lines · Alyssa Rosenzweig
Since the other patches went thru drm-misc-next, I guess this should too?
I think yes.
Yes, it would be ideal to add this to drm-misc-next as well.
Best Regards,
Petr
Quoted 4 lines · Petr Mladek
Quoted 3 lines · Aditya Garg
On 28-04-2025 10:30 pm, Alyssa Rosenzweig wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Since the other patches went thru drm-misc-next, I guess this should too?
I think yes.
Yes, it would be ideal to add this to drm-misc-next as well.
ok, will queue this
Hi Petr
Quoted 20 lines
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
Unfortunately, it creates confusion on big endian systems. For example, it shows the data &(u32)0x67503030 as
%p4cn 00Pg (0x30305067)But people expect that the ordering stays the same. The network ordering is a big-endian ordering.
The problem is that the semantic is not the same. The modifiers affect the output ordering of IPv4 addresses while they affect the reading order in case of FourCC code.
Quoted 8 lines
Avoid the confusion by replacing the "n" modifier with "hR", aka reverse host ordering. It is inspired by the existing %p[mM]R printf format.
Reported-by Geert Uytterhoeven <[email protected]>Closes https://lore.kernel.org/r/CAMuHMdV9tX=TG7E_CrSF=2PY206tXf+_yYRuacG48EWEtJLo-Q@mail.gmail.com open hereSigned-off-by Petr Mladek <[email protected]>---
I just realised you forgot to fix checkpatch.pl with your update:
Alyssa Rosenzweig
AppliedQuoted 9 lines · Petr Mladek
The generic FourCC format always prints the data using the big endian order. It is generic because it allows to read the data using a custom ordering.
The current code uses "n" for reading data in the reverse host ordering. It makes the 4 variants [hnbl] consistent with the generic printing of IPv4 addresses.
[...]
Applied, thanks!
[1/1] vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering
commit: 37eed892cc5ff36aeee59bb78f6aa417a44030a9
Best regards,
Signature · 1 line
Alyssa Rosenzweig <[email protected]>
PATCH 1/1 checkpatch: remove %p4cn
In reply to Petr Mladek%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -6891,7 +6891,7 @@ sub process { ($extension eq "f" && defined $qualifier && $qualifier !~ /^w/) || ($extension eq "4" && - defined $qualifier && $qualifier !~ /^c[hnlbc]/)) { + defined $qualifier && $qualifier !~ /^c[hlbc]/)) { $bad_specifier = $specifier; last; }
Signature · 1 line
2.49.0
Joe Perches
maintainerRe: [PATCH] checkpatch: remove %p4cn
Quoted 15 lines · Aditya Garg
%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
Fixes 37eed892cc5f ("vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering")Signed-off-by Aditya Garg <[email protected]>--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl sub process { · line 6894
Quoted 5 lines
scripts/checkpatch.pl +1
-1@@ -6891,7 +6891,7 @@ sub process { ($extension eq "f" && defined $qualifier && $qualifier !~ /^w/) || ($extension eq "4" && - defined $qualifier && $qualifier !~ /^c[hnlbc]/)) { + defined $qualifier && $qualifier !~ /^c[hlbc]/)) {
Probably needs to be something like:
$qualifier !~ /^c(?:[hlbc]|cR)$/
Quoted 3 lines
scripts/checkpatch.pl +0
-0$bad_specifier = $specifier; last; }
Re: [PATCH] checkpatch: remove %p4cn
Quoted 24 lines · Joe Perches
Quoted 15 lines · Aditya Garg
%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
Fixes 37eed892cc5f ("vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering")Signed-off-by Aditya Garg <[email protected]>--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/checkpatch.pl +0
-0scripts/checkpatch.pl sub process { · line 6894
Quoted 5 lines
scripts/checkpatch.pl +1
-1@@ -6891,7 +6891,7 @@ sub process { ($extension eq "f" && defined $qualifier && $qualifier !~ /^w/) || ($extension eq "4" && - defined $qualifier && $qualifier !~ /^c[hnlbc]/)) { + defined $qualifier && $qualifier !~ /^c[hlbc]/)) {Probably needs to be something like:
Quoted 1 line
$qualifier !~ /^c(?:[hlbc]|cR)$/
$qualifier !~ /^c(?:[hlbc]|hR)$/
I'll send a v2
Quoted 5 lines
Quoted 4 lines
scripts/checkpatch.pl +0
-0$bad_specifier = $specifier; last; }
PATCH v3 1/1 checkpatch: remove %p4cn
In reply to Aditya Garg%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
---
v2: Add specific check for %p4chR as suggested by Joe Perches.
v3: Remove blank lines from the tag block.
scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -6891,7 +6891,7 @@ sub process { ($extension eq "f" && defined $qualifier && $qualifier !~ /^w/) || ($extension eq "4" && - defined $qualifier && $qualifier !~ /^c[hnlbc]/)) { + defined $qualifier && $qualifier !~ /^c(?:[hlbc]|hR)$/)) { $bad_specifier = $specifier; last; }
Signature · 1 line
2.49.0
Re: [PATCH v3] checkpatch: remove %p4cn
Quoted 5 lines · Aditya Garg
%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
Fixes 37eed892cc5f ("vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering")Signed-off-by Aditya Garg <[email protected]>
Looks and works well:
Alyssa, could you please queue this one via drm-misc-next as well?
Best Regards,
Petr
PS: Aditya, thanks a lot for stepping in and providing this patch. Also
thanks others for shaping in. I was not able to react quickly. I had technical problems with my workstation and public holidays.
Alyssa Rosenzweig
AppliedRe: [PATCH v3] checkpatch: remove %p4cn
In reply to Aditya GargQuoted 4 lines · Aditya Garg
%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
Applied, thanks!
[1/1] checkpatch: remove %p4cn
commit: a6c0a91ccb257eaec2aee080df06863ce7601315
Best regards,
Signature · 1 line
Alyssa Rosenzweig <[email protected]>
PATCH v2 1/1 checkpatch: remove %p4cn and add check for %p4chR
In reply to Petr Mladek%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
---
v2: Add specific check for %p4chR as suggested by Joe Perches.
scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -6891,7 +6891,7 @@ sub process { ($extension eq "f" && defined $qualifier && $qualifier !~ /^w/) || ($extension eq "4" && - defined $qualifier && $qualifier !~ /^c[hnlbc]/)) { + defined $qualifier && $qualifier !~ /^c(?:[hlbc]|hR)$/)) { $bad_specifier = $specifier; last; }
Signature · 1 line
2.49.0
Andy Shevchenko
reviewerRe: [PATCH v2] checkpatch: remove %p4cn and add check for %p4chR
Quoted 2 lines · Aditya Garg
%p4cn was recently removed and replaced by %p4chR in vsprintf. So, remove the check for %p4cn from checkpatch.pl.
...
Quoted 3 lines
Fixes 37eed892cc5f ("vsprintf: Use %p4chR instead of %p4cn for reading data in reversed host ordering")
There shouldn't be blank lines in the tag block.
Quoted 1 line
Signed-off-by Aditya Garg <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko