[PATCH 4/7] efi/libstub: Avoid efi_puts() for compile time constant strings

From: Ard Biesheuvel

Date: Sun Sep 06 2026 - 09:11:31 EST


efi_puts() performs a UTF-8 to UTF-16 conversion on its input, as the
EFI console's native character set is UTF-16.

This is pointless for compile time constant strings, since we can
simply define those as UTF-16 to begin with.

Note that efi_puts() also performs LF to CR-LF conversion, so this needs
to be taken into account as well.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
drivers/firmware/efi/libstub/gop.c | 6 +++---
drivers/firmware/efi/libstub/printk.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index 80dc8cfeb33e..6919e28ba92b 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -309,12 +309,12 @@ static u32 choose_mode_list(efi_graphics_output_protocol_t *gop)
efi_status_t status;

efi_printk("Available graphics modes are 0-%u\n", max_mode-1);
- efi_puts(" * = current mode\n"
- " - = unusable mode\n");
+ efi_char16_puts(L" * = current mode\r\n"
+ " - = unusable mode\r\n");

choose_mode(gop, match_list, (void *)cur_mode);

- efi_puts("\nPress any key to continue (or wait 10 seconds)\n");
+ efi_char16_puts(L"\r\nPress any key to continue (or wait 10 seconds)\r\n");
status = efi_wait_for_key(10 * EFI_USEC_PER_SEC, &key);
if (status != EFI_SUCCESS && status != EFI_TIMEOUT) {
efi_err("Unable to read key, continuing in 10 seconds\n");
diff --git a/drivers/firmware/efi/libstub/printk.c b/drivers/firmware/efi/libstub/printk.c
index bc599212c05d..f36639886d00 100644
--- a/drivers/firmware/efi/libstub/printk.c
+++ b/drivers/firmware/efi/libstub/printk.c
@@ -136,7 +136,7 @@ int efi_printk(const char *fmt, ...)
return 0;

if (loglevel >= 0)
- efi_puts("EFI stub: ");
+ efi_char16_puts(L"EFI stub: ");

fmt = printk_skip_level(fmt);

@@ -146,7 +146,7 @@ int efi_printk(const char *fmt, ...)

efi_puts(printf_buf);
if (printed >= sizeof(printf_buf)) {
- efi_puts("[Message truncated]\n");
+ efi_char16_puts(L"[Message truncated]\r\n");
return -1;
}

--
2.47.3