summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2026-09-06 13:45:03 +0200
committerArd Biesheuvel <ardb@kernel.org>2026-10-04 21:53:57 +0200
commit13e7fd357fc537be221dbf5600fc663727733dbc (patch)
tree3be6247d767d0f889997183deab673e17c548162 /drivers
parent615afe6fa3bbe2e81fd9c7893c5a50b123246605 (diff)
efi/libstub: Add efi_snprintf() to construct wide strings
The native EFI character set is UTF-16 (or in practice, UCS-2). Implement efi_snprintf() to construct UTF-16 strings using printf style templates. This will be used in a subsequent patch to set the LoaderDevicePartUUID EFI variable. Reviewed-by: Vincent Mailhol <mailhol@kernel.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/firmware/efi/libstub/efistub.h1
-rw-r--r--drivers/firmware/efi/libstub/vsprintf.c11
2 files changed, 12 insertions, 0 deletions
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 36056c624782..880c1d0c464b 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1084,6 +1084,7 @@ int efi_vsnprintf(efi_char16_t *buf, size_t size, const char *fmt, va_list ap,
bool crlf);
__printf(1, 2) int efi_printk(char const *fmt, ...);
+__printf(3, 4) int efi_snprintf(efi_char16_t *buf, size_t size, const char *fmt, ...);
void efi_free(unsigned long size, unsigned long addr);
DEFINE_FREE(efi_pool, void *, if (_T) efi_bs_call(free_pool, _T));
diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c
index 7f6b891a338a..7fd6589f44ef 100644
--- a/drivers/firmware/efi/libstub/vsprintf.c
+++ b/drivers/firmware/efi/libstub/vsprintf.c
@@ -509,3 +509,14 @@ fail:
return pos;
}
+
+int efi_snprintf(efi_char16_t *buf, size_t size, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i = efi_vsnprintf(buf, size, fmt, args, false);
+ va_end(args);
+ return i;
+}