lib/vsprintf: Add support for generic FOURCCs by extending %p4cc
authorHector Martin <marcan@marcan.st>
Mon, 31 Jan 2022 15:40:51 +0000 (00:40 +0900)
committerJens Axboe <axboe@kernel.dk>
Tue, 1 Mar 2022 17:52:57 +0000 (10:52 -0700)
commit4168734dceee6218086cf4ec607bbfd7f1783db6
tree3fc10a257ae112171ee93d71c6a3bbb97ad05017
parente6ada6df471f847da3b09b357e246c62335bc0bb
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
an integer. Extend it to add format specifiers for printing generic
32-bit FOURCCs with various endian semantics:

%p4ch   Host-endian
%p4cl Little-endian
%p4cb Big-endian
%p4cr Reverse-endian

The endianness determines how bytes are interpreted as a u32, and the
FOURCC is then always printed MSByte-first (this is the opposite of
V4L/DRM FOURCCs). This covers most practical cases, e.g. %p4cr would
allow printing LSByte-first FOURCCs stored in host endian order
(other than the hex form being in character order, not the integer
value).

Signed-off-by: Hector Martin <marcan@marcan.st>
Documentation/core-api/printk-formats.rst
lib/vsprintf.c