1- From 4870ca09f6de64bb971ba649fc5b65b116b1d851 Mon Sep 17 00:00:00 2001
1+ From 0af1fbc1dcf698e9facfaabd9f0dd7395a7cb849 Mon Sep 17 00:00:00 2001
22From: Hector Martin <marcan@marcan.st>
33Date: Tue, 8 Apr 2025 12:17:57 +0530
4- Subject: [PATCH 1/2] lib/vsprintf: Add support for generic FourCCs by
5- extending %p4cc
4+ Subject: [PATCH 1/2] lib/vsprintf: Add support for generic FourCCs by extending
5+ %p4cc
66
77%p4cc is designed for DRM/V4L2 FourCCs with their specific quirks, but
88it's useful to be able to print generic 4-character codes formatted as
@@ -29,13 +29,13 @@ Signed-off-by: Hector Martin <marcan@marcan.st>
2929Signed-off-by: Aditya Garg <gargaditya08@live.com>
3030Reviewed-by: Kees Cook <kees@kernel.org>
3131---
32- Documentation/core-api/printk-formats.rst | 32 +++++++++++++++++++++
33- lib/vsprintf.c | 35 +++++++++++++++++++----
32+ Documentation/core-api/printk-formats.rst | 32 ++++++++++++++++++
33+ lib/vsprintf.c | 40 +++++++++++++++++++----
3434 scripts/checkpatch.pl | 2 +-
35- 3 files changed, 62 insertions(+), 7 deletions(-)
35+ 3 files changed, 67 insertions(+), 7 deletions(-)
3636
3737diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
38- index ecccc0473..bd420e8aa 100644
38+ index ecccc0473..7379d7ba1 100644
3939--- a/Documentation/core-api/printk-formats.rst
4040+++ b/Documentation/core-api/printk-formats.rst
4141@@ -648,6 +648,38 @@ Examples::
@@ -46,42 +46,42 @@ index ecccc0473..bd420e8aa 100644
4646+ -------------------
4747+
4848+ ::
49- + %p4c[hnlb ] gP00 (0x67503030)
49+ + %p4c[h[R]lb ] gP00 (0x67503030)
5050+
5151+ Print a generic FourCC code, as both ASCII characters and its numerical
5252+ value as hexadecimal.
5353+
5454+ The generic FourCC code is always printed in the big-endian format,
5555+ the most significant byte first. This is the opposite of V4L/DRM FourCCs.
5656+
57- + The additional ``h``, ``n ``, ``l``, and ``b`` specifiers define what
57+ + The additional ``h``, ``hR ``, ``l``, and ``b`` specifiers define what
5858+ endianness is used to load the stored bytes. The data might be interpreted
59- + using the host byte order, network byte order, little-endian, or big-endian.
59+ + using the host, reversed host byte order, little-endian, or big-endian.
6060+
6161+ Passed by reference.
6262+
6363+ Examples for a little-endian machine, given &(u32)0x67503030::
6464+
6565+ %p4ch gP00 (0x67503030)
66- + %p4cn 00Pg (0x30305067)
66+ + %p4chR 00Pg (0x30305067)
6767+ %p4cl gP00 (0x67503030)
6868+ %p4cb 00Pg (0x30305067)
6969+
7070+ Examples for a big-endian machine, given &(u32)0x67503030::
7171+
7272+ %p4ch gP00 (0x67503030)
73- + %p4cn 00Pg (0x30305067)
73+ + %p4chR 00Pg (0x30305067)
7474+ %p4cl 00Pg (0x30305067)
7575+ %p4cb gP00 (0x67503030)
7676+
7777 Rust
7878 ----
7979
8080diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81- index a8ac4c4ff..a434b58e8 100644
81+ index a8ac4c4ff..67cf6c542 100644
8282--- a/lib/vsprintf.c
8383+++ b/lib/vsprintf.c
84- @@ -1781,27 +1781,50 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
84+ @@ -1781,27 +1781,49 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
8585 char output[sizeof("0123 little-endian (0x01234567)")];
8686 char *p = output;
8787 unsigned int i;
@@ -99,9 +99,8 @@ index a8ac4c4ff..a434b58e8 100644
9999- val = orig & ~BIT(31);
100100+ switch (fmt[2]) {
101101+ case 'h':
102- + break;
103- + case 'n':
104- + orig = swab32(orig);
102+ + if (fmt[3] == 'R')
103+ + orig = swab32(orig);
105104+ break;
106105+ case 'l':
107106+ orig = (__force u32)cpu_to_le32(orig);
@@ -138,6 +137,19 @@ index a8ac4c4ff..a434b58e8 100644
138137
139138 *p++ = ' ';
140139 *p++ = '(';
140+ @@ -2365,6 +2387,12 @@ char *rust_fmt_argument(char *buf, char *end, const void *ptr);
141+ * read the documentation (path below) first.
142+ * - 'NF' For a netdev_features_t
143+ * - '4cc' V4L2 or DRM FourCC code, with endianness and raw numerical value.
144+ + * - '4c[h[R]lb]' For generic FourCC code with raw numerical value. Both are
145+ + * displayed in the big-endian format. This is the opposite of V4L2 or
146+ + * DRM FourCCs.
147+ + * The additional specifiers define what endianness is used to load
148+ + * the stored bytes. The data might be interpreted using the host,
149+ + * reversed host byte order, little-endian, or big-endian.
150+ * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
151+ * a certain separator (' ' by default):
152+ * C colon
141153diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
142154index 7b28ad331..5595a0898 100755
143155--- a/scripts/checkpatch.pl
0 commit comments