-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d1375b
commit c5ab9f6
Showing
1 changed file
with
74 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
From f6ab7e4580962c9d82e7dc40dd074d47b2bce034 Mon Sep 17 00:00:00 2001 | ||
From ddaaa1980bdc62568453c468e1c8512713d8a13b Mon Sep 17 00:00:00 2001 | ||
From: Hector Martin <[email protected]> | ||
Date: Tue, 1 Feb 2022 00:40:51 +0900 | ||
Subject: [PATCH 09/12] lib/vsprintf: Add support for generic FOURCCs by | ||
extending %p4cc | ||
Date: Tue, 8 Nov 2022 16:33:22 +0000 | ||
Subject: [PATCH] lib/vsprintf: Add support for generic FOURCCs by extending | ||
%p4cc | ||
|
||
%p4cc is designed for DRM/V4L2 FOURCCs with their specific quirks, but | ||
it's useful to be able to print generic 4-character codes formatted as | ||
|
@@ -22,27 +22,26 @@ allow printing LSByte-first FOURCCs stored in host endian order | |
value). | ||
|
||
Signed-off-by: Hector Martin <[email protected]> | ||
Signed-off-by: Kerem Karabay <[email protected]> | ||
Signed-off-by: Russell King (Oracle) <[email protected]> | ||
--- | ||
Documentation/core-api/printk-formats.rst | 32 ++++++++++++++++++++ | ||
lib/test_printf.c | 20 +++++++++---- | ||
lib/vsprintf.c | 36 +++++++++++++++++++---- | ||
scripts/checkpatch.pl | 2 +- | ||
4 files changed, 77 insertions(+), 13 deletions(-) | ||
Documentation/core-api/printk-formats.rst | 32 +++++++++++++++++++ | ||
lib/test_printf.c | 39 +++++++++++++++++++---- | ||
lib/vsprintf.c | 38 ++++++++++++++++++---- | ||
3 files changed, 96 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst | ||
index dfe7e75a7..0ccef63e6 100644 | ||
index ecccc0473..9982861fa 100644 | ||
--- a/Documentation/core-api/printk-formats.rst | ||
+++ b/Documentation/core-api/printk-formats.rst | ||
@@ -631,6 +631,38 @@ Examples:: | ||
@@ -648,6 +648,38 @@ Examples:: | ||
%p4cc Y10 little-endian (0x20303159) | ||
%p4cc NV12 big-endian (0xb231564e) | ||
|
||
+Generic FourCC code | ||
+------------------- | ||
+ | ||
+:: | ||
+ %p4c[hnbl] gP00 (0x67503030) | ||
+ %p4c[hrbl] gP00 (0x67503030) | ||
+ | ||
+Print a generic FourCC code, as both ASCII characters and its numerical | ||
+value as hexadecimal. | ||
|
@@ -59,66 +58,87 @@ index dfe7e75a7..0ccef63e6 100644 | |
+Examples for a little-endian machine, given &(u32)0x67503030:: | ||
+ | ||
+ %p4ch gP00 (0x67503030) | ||
+ %p4cl gP00 (0x67503030) | ||
+ %p4cb 00Pg (0x30305067) | ||
+ %p4cr 00Pg (0x30305067) | ||
+ %p4cb 00Pg (0x30305067) | ||
+ %p4cl gP00 (0x67503030) | ||
+ | ||
+Examples for a big-endian machine, given &(u32)0x67503030:: | ||
+ | ||
+ %p4ch gP00 (0x67503030) | ||
+ %p4cl 00Pg (0x30305067) | ||
+ %p4cb gP00 (0x67503030) | ||
+ %p4cr 00Pg (0x30305067) | ||
+ %p4cb gP00 (0x67503030) | ||
+ %p4cl 00Pg (0x30305067) | ||
+ | ||
Rust | ||
---- | ||
|
||
diff --git a/lib/test_printf.c b/lib/test_printf.c | ||
index 7677ebccf..2355be36f 100644 | ||
index 59dbe4f9a..ee860327e 100644 | ||
--- a/lib/test_printf.c | ||
+++ b/lib/test_printf.c | ||
@@ -746,18 +746,26 @@ static void __init fwnode_pointer(void) | ||
@@ -776,21 +776,46 @@ static void __init fwnode_pointer(void) | ||
software_node_unregister_node_group(group); | ||
} | ||
|
||
+struct fourcc_struct { | ||
+ u32 code; | ||
+ const char *str; | ||
+}; | ||
+ | ||
+static void __init fourcc_pointer_test(const struct fourcc_struct *fc, size_t n, | ||
+ const char *fmt) | ||
+{ | ||
+ size_t i; | ||
+ | ||
+ for (i = 0; i < n; i++) | ||
+ test(fc[i].str, fmt, &fc[i].code); | ||
+} | ||
+ | ||
static void __init fourcc_pointer(void) | ||
{ | ||
struct { | ||
+ char type; | ||
u32 code; | ||
char *str; | ||
} const try[] = { | ||
- { 0x3231564e, "NV12 little-endian (0x3231564e)", }, | ||
- { 0xb231564e, "NV12 big-endian (0xb231564e)", }, | ||
- { 0x10111213, ".... little-endian (0x10111213)", }, | ||
- { 0x20303159, "Y10 little-endian (0x20303159)", }, | ||
+ { 'c', 0x3231564e, "NV12 little-endian (0x3231564e)", }, | ||
+ { 'c', 0xb231564e, "NV12 big-endian (0xb231564e)", }, | ||
+ { 'c', 0x10111213, ".... little-endian (0x10111213)", }, | ||
+ { 'c', 0x20303159, "Y10 little-endian (0x20303159)", }, | ||
+ { 'h', 0x67503030, "gP00 (0x67503030)", }, | ||
+ { 'r', 0x30305067, "gP00 (0x67503030)", }, | ||
+ { 'l', cpu_to_le32(0x67503030), "gP00 (0x67503030)", }, | ||
+ { 'b', cpu_to_be32(0x67503030), "gP00 (0x67503030)", }, | ||
- struct { | ||
- u32 code; | ||
- char *str; | ||
- } const try[] = { | ||
+ struct fourcc_struct const try_cc[] = { | ||
{ 0x3231564e, "NV12 little-endian (0x3231564e)", }, | ||
{ 0xb231564e, "NV12 big-endian (0xb231564e)", }, | ||
{ 0x10111213, ".... little-endian (0x10111213)", }, | ||
{ 0x20303159, "Y10 little-endian (0x20303159)", }, | ||
}; | ||
unsigned int i; | ||
- unsigned int i; | ||
+ struct fourcc_struct const try_ch = { | ||
+ 0x41424344, "ABCD (0x41424344)", | ||
+ }; | ||
+ struct fourcc_struct const try_cr = { | ||
+ 0x41424344, "DCBA (0x44434241)", | ||
+ }; | ||
+ struct fourcc_struct const try_cl = { | ||
+ le32_to_cpu(0x41424344), "ABCD (0x41424344)", | ||
+ }; | ||
+ struct fourcc_struct const try_cb = { | ||
+ be32_to_cpu(0x41424344), "ABCD (0x41424344)", | ||
+ }; | ||
|
||
- for (i = 0; i < ARRAY_SIZE(try); i++) | ||
- test(try[i].str, "%p4cc", &try[i].code); | ||
+ for (i = 0; i < ARRAY_SIZE(try); i++) { | ||
+ char fmt[] = { '%', 'p', '4', 'c', try[i].type, '\0' }; | ||
+ | ||
+ test(try[i].str, fmt, &try[i].code); | ||
+ } | ||
+ fourcc_pointer_test(try_cc, ARRAY_SIZE(try_cc), "%p4cc"); | ||
+ fourcc_pointer_test(&try_ch, 1, "%p4ch"); | ||
+ fourcc_pointer_test(&try_cr, 1, "%p4cr"); | ||
+ fourcc_pointer_test(&try_cl, 1, "%p4cl"); | ||
+ fourcc_pointer_test(&try_cb, 1, "%p4cb"); | ||
} | ||
|
||
static void __init | ||
diff --git a/lib/vsprintf.c b/lib/vsprintf.c | ||
index 40f560959..bd9af783c 100644 | ||
index 56fe96319..13733a4da 100644 | ||
--- a/lib/vsprintf.c | ||
+++ b/lib/vsprintf.c | ||
@@ -1758,27 +1758,50 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, | ||
@@ -1781,27 +1781,53 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, | ||
char output[sizeof("0123 little-endian (0x01234567)")]; | ||
char *p = output; | ||
unsigned int i; | ||
+ bool pix_fmt = false; | ||
+ bool pixel_fmt = false; | ||
u32 orig, val; | ||
|
||
- if (fmt[1] != 'c' || fmt[2] != 'c') | ||
|
@@ -135,18 +155,21 @@ index 40f560959..bd9af783c 100644 | |
+ val = orig; | ||
+ break; | ||
+ case 'r': | ||
+ val = orig = swab32(orig); | ||
+ orig = swab32(orig); | ||
+ val = orig; | ||
+ break; | ||
+ case 'l': | ||
+ val = orig = le32_to_cpu(orig); | ||
+ orig = le32_to_cpu(orig); | ||
+ val = orig; | ||
+ break; | ||
+ case 'b': | ||
+ val = orig = be32_to_cpu(orig); | ||
+ orig = be32_to_cpu(orig); | ||
+ val = orig; | ||
+ break; | ||
+ case 'c': | ||
+ /* Pixel formats are printed LSB-first */ | ||
+ val = swab32(orig & ~BIT(31)); | ||
+ pix_fmt = true; | ||
+ pixel_fmt = true; | ||
+ break; | ||
+ default: | ||
+ return error_string(buf, end, "(%p4?)", spec); | ||
|
@@ -163,35 +186,14 @@ index 40f560959..bd9af783c 100644 | |
- *p++ = ' '; | ||
- strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); | ||
- p += strlen(p); | ||
+ if (pix_fmt) { | ||
+ if (pixel_fmt) { | ||
+ *p++ = ' '; | ||
+ strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); | ||
+ p += strlen(p); | ||
+ } | ||
|
||
*p++ = ' '; | ||
*p++ = '('; | ||
@@ -2348,6 +2371,7 @@ char *rust_fmt_argument(char *buf, char *end, void *ptr); | ||
* 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[hlbr]' Generic FourCC code. | ||
* - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with | ||
* a certain separator (' ' by default): | ||
* C colon | ||
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl | ||
index 880fde13d..f080e33a4 100755 | ||
--- a/scripts/checkpatch.pl | ||
+++ b/scripts/checkpatch.pl | ||
@@ -6906,7 +6906,7 @@ sub process { | ||
($extension eq "f" && | ||
defined $qualifier && $qualifier !~ /^w/) || | ||
($extension eq "4" && | ||
- defined $qualifier && $qualifier !~ /^cc/)) { | ||
+ defined $qualifier && $qualifier !~ /^c[chlbr]/)) { | ||
$bad_specifier = $specifier; | ||
last; | ||
} | ||
-- | ||
2.42.0 | ||
2.47.1 | ||
|