[PATCH 6/7] efi/libstub: Add support for printing human readable GUIDs

From: Ard Biesheuvel

Date: Sun Sep 06 2026 - 09:08:54 EST


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@xxxxxxxxxx>
Signed-off-by: Vincent Mailhol <mailhol@xxxxxxxxxx>
Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
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