]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: make console_key_read() return param optional
authorLennart Poettering <lennart@poettering.net>
Tue, 6 May 2025 13:05:05 +0000 (15:05 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 6 May 2025 15:38:25 +0000 (17:38 +0200)
Inspired by #36684

src/boot/console.c
src/boot/secure-boot.c

index b174146cdf0a6e13d27fe0170823b68676cda875..5e11ba54249f40fc7c1819719bf7ba3d13584693 100644 (file)
@@ -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;
         }
 
index 1fdb1e2c3446e4750b1e27a6e60d10ad107629c1..b6948586e52bdc85ef9e2fffb8bccca54d74d3fb 100644 (file)
@@ -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) {