Skip to content

Commit 9b5febf

Browse files
committed
Update vsprintf
1 parent 6621054 commit 9b5febf

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

1013-lib-vsprintf-Add-support-for-generic-FourCCs-by-exte.patch

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
From 82cefe589ff158b99f33996ad085f0739bff6a4a Mon Sep 17 00:00:00 2001
1+
From ffee86d17b463d4e2bcc1070dc1d03dc88870bc4 Mon Sep 17 00:00:00 2001
22
From: Hector Martin <[email protected]>
33
Date: 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
88
it's useful to be able to print generic 4-character codes formatted as
@@ -29,13 +29,13 @@ Signed-off-by: Hector Martin <[email protected]>
2929
Signed-off-by: Aditya Garg <[email protected]>
3030
Reviewed-by: Kees Cook <[email protected]>
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

3737
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
38-
index 14e093da3..0cecb822d 100644
38+
index 14e093da3..99df8d175 100644
3939
--- a/Documentation/core-api/printk-formats.rst
4040
+++ b/Documentation/core-api/printk-formats.rst
4141
@@ -630,6 +630,38 @@ Examples::
@@ -46,42 +46,42 @@ index 14e093da3..0cecb822d 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

8080
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81-
index a69e71a1c..6853d47a6 100644
81+
index c5e2ec930..af0fd89cb 100644
8282
--- a/lib/vsprintf.c
8383
+++ b/lib/vsprintf.c
84-
@@ -1760,27 +1760,50 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc,
84+
@@ -1760,27 +1760,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 a69e71a1c..6853d47a6 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 a69e71a1c..6853d47a6 100644
138137

139138
*p++ = ' ';
140139
*p++ = '(';
140+
@@ -2334,6 +2356,12 @@ char *rust_fmt_argument(char *buf, char *end, 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
141153
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
142154
index b03d526e4..e6d854f56 100755
143155
--- a/scripts/checkpatch.pl

0 commit comments

Comments
 (0)