From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Vincent Mailhol <mailhol@kernel.org>,
x86@kernel.org
Subject: [PATCH 6/7] efi/libstub: Add support for printing human readable GUIDs
Date: Sun, 6 Sep 2026 15:08:24 +0200 [thread overview]
Message-ID: <20260906130817.1151961-15-ardb@kernel.org> (raw)
In-Reply-To: <20260906130817.1151961-9-ardb@kernel.org>
Add support for the %pUl printk conversion specifier, which takes a
pointer to a GUID and prints it in the usual format:
aaaaaaaa-bbbb-cccc-dddd-dddddddddddd
Co-developed-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/vsprintf.c | 40 +++++++++++++++++---
1 file changed, 35 insertions(+), 5 deletions(-)
diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c
index 9ac6df268105..4c11cee6c722 100644
--- a/drivers/firmware/efi/libstub/vsprintf.c
+++ b/drivers/firmware/efi/libstub/vsprintf.c
@@ -111,6 +111,9 @@ char *put_dec(char *end, unsigned long long n)
return p;
}
+/* we are called with base 8, 10 or 16, only, thus don't need "G..." */
+static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
+
static
char *number(char *end, unsigned long long num, int base, char locase)
{
@@ -119,9 +122,6 @@ char *number(char *end, unsigned long long num, int base, char locase)
* produces same digits or (maybe lowercased) letters
*/
- /* we are called with base 8, 10 or 16, only, thus don't need "G..." */
- static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
-
switch (base) {
case 10:
if (num != 0)
@@ -142,6 +142,29 @@ char *number(char *end, unsigned long long num, int base, char locase)
return end;
}
+static char *guid_to_str(const efi_guid_t *guid, char *out, char locase)
+{
+ static const u8 guid_index[UUID_SIZE] = {
+ 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15,
+ };
+
+ for (int i = 0, p = 0; i < ARRAY_SIZE(guid_index); i++) {
+ u8 byte = guid->b[guid_index[i]];
+
+ out[p++] = locase | digits[byte >> 4];
+ out[p++] = locase | digits[byte & 0xf];
+
+ switch (i) {
+ case 3:
+ case 5:
+ case 7:
+ case 9:
+ out[p++] = '-';
+ }
+ }
+ return out;
+}
+
#define ZEROPAD 1 /* pad with zero */
#define SIGN 2 /* unsigned/signed long */
#define PLUS 4 /* show plus */
@@ -251,8 +274,7 @@ do { \
int efi_vsnprintf(efi_char16_t *buf, size_t size, const char *fmt, va_list ap,
bool crlf)
{
- /* The maximum space required is to print a 64-bit number in octal */
- char tmp[(sizeof(unsigned long long) * 8 + 2) / 3];
+ char tmp[UUID_STRING_LEN];
char *tmp_end = &tmp[ARRAY_SIZE(tmp)];
long long num;
int base;
@@ -365,6 +387,14 @@ int efi_vsnprintf(efi_char16_t *buf, size_t size, const char *fmt, va_list ap,
break;
case 'p':
+ if (fmt[1] == 'U' && (fmt[2] | 0x20) == 'l') {
+ flags &= LEFT;
+ s = guid_to_str(va_arg(args, efi_guid_t *), tmp, fmt[2] & 0x20);
+ precision = len = UUID_STRING_LEN;
+ fmt += 2;
+ goto output;
+ }
+
if (precision < 0)
precision = 2 * sizeof(void *);
fallthrough;
--
2.47.3
next prev parent reply other threads:[~2026-09-06 13:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-06 13:08 [PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 1/7] x86/boot: Drop pointless re-implementation of panic() Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 2/7] lib/ucs2_string: Avoid WARN in library code Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 3/7] efi/libstub: Use ucs2_string library for UTF-16 to UTF-8 conversion Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 4/7] efi/libstub: Avoid efi_puts() for compile time constant strings Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 5/7] efi/libstub: Output UTF-16 directly from vsnprintf() Ard Biesheuvel
2026-09-09 12:46 ` David Laight
2026-09-06 13:08 ` Ard Biesheuvel [this message]
2026-09-06 13:08 ` [PATCH 7/7] efi/libstub: Add efi_snprintf() to construct wide strings Ard Biesheuvel
2026-09-06 22:14 ` [PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork Vincent Mailhol
2026-09-08 17:24 ` [PATCH] efi: pass NUL-inclusive sizes to ucs2_as_utf8() Vincent Mailhol
2026-09-09 11:38 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260906130817.1151961-15-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®