1
- From 82cefe589ff158b99f33996ad085f0739bff6a4a Mon Sep 17 00:00:00 2001
1
+ From ffee86d17b463d4e2bcc1070dc1d03dc88870bc4 Mon Sep 17 00:00:00 2001
2
2
From: Hector Martin <
[email protected] >
3
3
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
6
6
7
7
%p4cc is designed for DRM/V4L2 FourCCs with their specific quirks, but
8
8
it's useful to be able to print generic 4-character codes formatted as
29
29
Signed-off-by: Aditya Garg <
[email protected] >
30
30
Reviewed-by: Kees Cook <
[email protected] >
31
31
---
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 +++++++++++++++++++----
34
34
scripts/checkpatch.pl | 2 +-
35
- 3 files changed, 62 insertions(+), 7 deletions(-)
35
+ 3 files changed, 67 insertions(+), 7 deletions(-)
36
36
37
37
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
39
39
--- a/Documentation/core-api/printk-formats.rst
40
40
+++ b/Documentation/core-api/printk-formats.rst
41
41
@@ -630,6 +630,38 @@ Examples::
@@ -46,42 +46,42 @@ index 14e093da3..0cecb822d 100644
46
46
+ -------------------
47
47
+
48
48
+ ::
49
- + %p4c[hnlb ] gP00 (0x67503030)
49
+ + %p4c[h[R]lb ] gP00 (0x67503030)
50
50
+
51
51
+ Print a generic FourCC code, as both ASCII characters and its numerical
52
52
+ value as hexadecimal.
53
53
+
54
54
+ The generic FourCC code is always printed in the big-endian format,
55
55
+ the most significant byte first. This is the opposite of V4L/DRM FourCCs.
56
56
+
57
- + The additional ``h``, ``n ``, ``l``, and ``b`` specifiers define what
57
+ + The additional ``h``, ``hR ``, ``l``, and ``b`` specifiers define what
58
58
+ 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.
60
60
+
61
61
+ Passed by reference.
62
62
+
63
63
+ Examples for a little-endian machine, given &(u32)0x67503030::
64
64
+
65
65
+ %p4ch gP00 (0x67503030)
66
- + %p4cn 00Pg (0x30305067)
66
+ + %p4chR 00Pg (0x30305067)
67
67
+ %p4cl gP00 (0x67503030)
68
68
+ %p4cb 00Pg (0x30305067)
69
69
+
70
70
+ Examples for a big-endian machine, given &(u32)0x67503030::
71
71
+
72
72
+ %p4ch gP00 (0x67503030)
73
- + %p4cn 00Pg (0x30305067)
73
+ + %p4chR 00Pg (0x30305067)
74
74
+ %p4cl 00Pg (0x30305067)
75
75
+ %p4cb gP00 (0x67503030)
76
76
+
77
77
Rust
78
78
----
79
79
80
80
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81
- index a69e71a1c..6853d47a6 100644
81
+ index c5e2ec930..af0fd89cb 100644
82
82
--- a/lib/vsprintf.c
83
83
+++ 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,
85
85
char output[sizeof("0123 little-endian (0x01234567)")];
86
86
char *p = output;
87
87
unsigned int i;
@@ -99,9 +99,8 @@ index a69e71a1c..6853d47a6 100644
99
99
- val = orig & ~BIT(31);
100
100
+ switch (fmt[2]) {
101
101
+ case 'h':
102
- + break;
103
- + case 'n':
104
- + orig = swab32(orig);
102
+ + if (fmt[3] == 'R')
103
+ + orig = swab32(orig);
105
104
+ break;
106
105
+ case 'l':
107
106
+ orig = (__force u32)cpu_to_le32(orig);
@@ -138,6 +137,19 @@ index a69e71a1c..6853d47a6 100644
138
137
139
138
*p++ = ' ';
140
139
*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
141
153
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
142
154
index b03d526e4..e6d854f56 100755
143
155
--- a/scripts/checkpatch.pl
0 commit comments