:: commit e9592014da19182c757bd6ee6d64d1a05d020ddf

Mintsuki <mintsuki@protonmail.com> — 2025-09-05 20:52

parents: 0ec87d3e47

drivers/disk: Only validate EFI handle before running the fallback detection method

diff --git a/common/drivers/disk.s2.c b/common/drivers/disk.s2.c
index 08141555..8169d9a4 100644
--- a/common/drivers/disk.s2.c
+++ b/common/drivers/disk.s2.c
@@ -442,10 +442,6 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE efi_handle) {
     EFI_GUID block_io_guid = BLOCK_IO_PROTOCOL;
     EFI_BLOCK_IO *block_io = NULL;
 
-    if (!validate_efi_handle(efi_handle)) {
-        return NULL;
-    }
-
     status = gBS->HandleProtocol(efi_handle, &block_io_guid, (void **)&block_io);
     if (status) {
         return pxe_from_efi_handle(efi_handle);
@@ -474,6 +470,10 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE efi_handle) {
 
     // Fallback to read-back method
 fallback:;
+    if (!validate_efi_handle(efi_handle)) {
+        return NULL;
+    }
+
     uint64_t signature = rand64();
     uint64_t new_signature;
     do { new_signature = rand64(); } while (new_signature == signature);
@@ -652,10 +652,6 @@ fail:
     for (size_t i = 0; i < handle_count; i++) {
         EFI_BLOCK_IO *drive = NULL;
 
-        if (!validate_efi_handle(handles[i])) {
-            continue;
-        }
-
         status = gBS->HandleProtocol(handles[i], &block_io_guid, (void **)&drive);
 
         if (status != 0 || drive == NULL || drive->Media->LastBlock == 0)
tab: 248 wrap: offon