diff options
author | Arvind Sankar <nivedita@alum.mit.edu> | 2020-05-18 15:06:55 -0400 |
---|---|---|
committer | Ard Biesheuvel <ardb@kernel.org> | 2020-05-19 09:23:22 +0200 |
commit | fd0528a24958b7e8d55669cf50749776308d4c5a (patch) | |
tree | aad5868e4ab5fa6ba23105c60a938f8ff2d6a690 /drivers | |
parent | cb8c90a08c7f2f761919190093fca0611c1cece4 (diff) |
efi/libstub: Buffer output of efi_puts
Use a buffer to convert the string to UTF-16. This will reduce the
number of firmware calls required to print the string from one per
character to one per string in most cases.
Cast the input char to unsigned char before converting to efi_char16_t
to avoid sign-extension in case there are any non-ASCII characters in
the input.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Link: https://lore.kernel.org/r/20200518190716.751506-4-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/firmware/efi/libstub/efi-stub-helper.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index c6d7ef35e9f7..3cf506ab9ead 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -8,6 +8,7 @@ */ #include <linux/efi.h> +#include <linux/kernel.h> #include <asm/efi.h> #include "efistub.h" @@ -34,13 +35,19 @@ void efi_char16_puts(efi_char16_t *str) void efi_puts(const char *str) { - while (*str) { - efi_char16_t ch[] = { *str++, L'\0' }; + efi_char16_t buf[128]; + size_t pos = 0, lim = ARRAY_SIZE(buf); - if (ch[0] == L'\n') - efi_char16_puts(L"\r\n"); - else - efi_char16_puts(ch); + while (*str) { + if (*str == '\n') + buf[pos++] = L'\r'; + /* Cast to unsigned char to avoid sign-extension */ + buf[pos++] = (unsigned char)(*str++); + if (*str == '\0' || pos >= lim - 2) { + buf[pos] = L'\0'; + efi_char16_puts(buf); + pos = 0; + } } } |