From e9f9ddbfa8ed9e115ace885e0931e0e41b26ed42 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 6 May 2025 15:05:05 +0200 Subject: [PATCH] boot: make console_key_read() return param optional Inspired by #36684 --- src/boot/console.c | 10 +++++----- src/boot/secure-boot.c | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/boot/console.c b/src/boot/console.c index b174146cdf0..5e11ba54249 100644 --- a/src/boot/console.c +++ b/src/boot/console.c @@ -35,15 +35,13 @@ static void event_closep(EFI_EVENT *event) { * will replace ConInEx permanently if it ever reports a key press. * Lastly, a timer event allows us to provide a input timeout without having to call into * any input functions that can freeze on us or using a busy/stall loop. */ -EFI_STATUS console_key_read(uint64_t *key, uint64_t timeout_usec) { +EFI_STATUS console_key_read(uint64_t *ret_key, uint64_t timeout_usec) { static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *conInEx = NULL, *extraInEx = NULL; static bool checked = false; size_t index; EFI_STATUS err; _cleanup_(event_closep) EFI_EVENT timer = NULL; - assert(key); - if (!checked) { /* Get the *first* TextInputEx device. */ err = BS->LocateProtocol( @@ -148,7 +146,8 @@ EFI_STATUS console_key_read(uint64_t *key, uint64_t timeout_usec) { } /* 32 bit modifier keys + 16 bit scan code + 16 bit unicode */ - *key = KEYPRESS(shift, keydata.Key.ScanCode, keydata.Key.UnicodeChar); + if (ret_key) + *ret_key = KEYPRESS(shift, keydata.Key.ScanCode, keydata.Key.UnicodeChar); return EFI_SUCCESS; } else if (BS->CheckEvent(ST->ConIn->WaitForKey) == EFI_SUCCESS) { EFI_INPUT_KEY k; @@ -157,7 +156,8 @@ EFI_STATUS console_key_read(uint64_t *key, uint64_t timeout_usec) { if (err != EFI_SUCCESS) return err; - *key = KEYPRESS(0, k.ScanCode, k.UnicodeChar); + if (ret_key) + *ret_key = KEYPRESS(0, k.ScanCode, k.UnicodeChar); return EFI_SUCCESS; } diff --git a/src/boot/secure-boot.c b/src/boot/secure-boot.c index 1fdb1e2c344..b6948586e52 100644 --- a/src/boot/secure-boot.c +++ b/src/boot/secure-boot.c @@ -94,8 +94,7 @@ EFI_STATUS secure_boot_enroll_at(EFI_FILE *root_dir, const char16_t *path, bool for (;;) { printf("\rEnrolling in %2u s, press any key to abort.", timeout_sec); - uint64_t key; - err = console_key_read(&key, 1000 * 1000); + err = console_key_read(/* ret_key= */ NULL, /* timeout_usec= */ 1000 * 1000); if (err == EFI_NOT_READY) continue; if (err == EFI_TIMEOUT) { -- 2.47.3