Skip to content

Commit fd0528a

Browse files
nivedita76ardbiesheuvel
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent cb8c90a commit fd0528a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <linux/efi.h>
11+
#include <linux/kernel.h>
1112
#include <asm/efi.h>
1213

1314
#include "efistub.h"
@@ -34,13 +35,19 @@ void efi_char16_puts(efi_char16_t *str)
3435

3536
void efi_puts(const char *str)
3637
{
37-
while (*str) {
38-
efi_char16_t ch[] = { *str++, L'\0' };
38+
efi_char16_t buf[128];
39+
size_t pos = 0, lim = ARRAY_SIZE(buf);
3940

40-
if (ch[0] == L'\n')
41-
efi_char16_puts(L"\r\n");
42-
else
43-
efi_char16_puts(ch);
41+
while (*str) {
42+
if (*str == '\n')
43+
buf[pos++] = L'\r';
44+
/* Cast to unsigned char to avoid sign-extension */
45+
buf[pos++] = (unsigned char)(*str++);
46+
if (*str == '\0' || pos >= lim - 2) {
47+
buf[pos] = L'\0';
48+
efi_char16_puts(buf);
49+
pos = 0;
50+
}
4451
}
4552
}
4653

0 commit comments

Comments
 (0)