From: David Laight <david.laight.linux@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
Vincent Mailhol <mailhol@kernel.org>,
x86@kernel.org
Subject: Re: [PATCH 5/7] efi/libstub: Output UTF-16 directly from vsnprintf()
Date: Wed, 9 Sep 2026 13:46:22 +0100 [thread overview]
Message-ID: <20260909134622.3ac54b52@pumpkin> (raw)
In-Reply-To: <20260906130817.1151961-14-ardb@kernel.org>
On Sun, 6 Sep 2026 15:08:23 +0200
Ard Biesheuvel <ardb@kernel.org> wrote:
> The only remaining users of vsnprintf() in the EFI stub are the
> diagnostic printk()'s, which are emitted to the console and not recorded
> for posterity.
>
> The EFI console uses UTF-16 (or actually, UCS-2) natively, and so all
> non-UTF16 strings that are emitted need to be converted. Given the
> stub's vsnprintf() support for wide strings (using the %ls conversion
> modifier), which uses UTF-16 to UTF-8 conversion internally, the final
> conversion to UTF-16 needs to support not just plain ASCII but UTF-8 as
> well.
>
> This is all pointless, of course, and it makes more sense to use UTF-16
> internally. This removes the need for UTF-16 to UTF-8 conversion in
> vsnprintf(), and given that all non-wide string inputs to vsnprintf()
> that exist in the stub today are compile time constant ASCII strings,
> the need to convert UTF-8 to UTF-16 disappears as well.
>
> So implement efi_vsnprintf() taking a const char *fmt as before, but
> outputting a efi_char16_t[] that can be passed to the EFI console
> directly, rather than via efi_puts(), leaving the latter unused and
> therefore removed.
>
> Note that efi_puts() performs LF to CR-LF conversion internally, so add
> this capability to efi_vsnprintf() as well.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
...
> /**
> * efi_printk() - Print a kernel message
> * @fmt: format string
> *
> * The first letter of the format string is used to determine the logging level
> * of the message. If the level is less then the current EFI logging level, the
> - * message is suppressed. The message will be truncated to 255 bytes.
> + * message is suppressed. The message will be truncated to 255 characters
> + * (ignoring surrogates).
> *
> * Return: number of printed characters
> */
> int efi_printk(const char *fmt, ...)
> {
> - char printf_buf[256];
> + efi_char16_t printf_buf[256];
> va_list args;
> int printed;
> int loglevel = printk_get_level(fmt);
> @@ -141,10 +63,11 @@ int efi_printk(const char *fmt, ...)
> fmt = printk_skip_level(fmt);
>
> va_start(args, fmt);
> - printed = vsnprintf(printf_buf, sizeof(printf_buf), fmt, args);
> + printed = efi_vsnprintf(printf_buf, ARRAY_SIZE(printf_buf), fmt, args,
> + true);
> va_end(args);
>
> - efi_puts(printf_buf);
> + efi_char16_puts(printf_buf);
> if (printed >= sizeof(printf_buf)) {
You missed that sizeof().
Be nice to have a note about the size not being in bytes.
David
next prev parent reply other threads:[~2026-09-09 12:46 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 [this message]
2026-09-06 13:08 ` [PATCH 6/7] efi/libstub: Add support for printing human readable GUIDs Ard Biesheuvel
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=20260909134622.3ac54b52@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.