]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_selftest_memory: check for duplicates first
authorRandolph Sapp <rs@ti.com>
Wed, 22 Apr 2026 17:09:44 +0000 (12:09 -0500)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Tue, 5 May 2026 14:29:08 +0000 (16:29 +0200)
Check for duplicate memory mappings before reporting any incorrect
attributes. Could be that second allocation has the correct type while
the first doesn't. Knowing there is a duplicate in this scenario is
more helpful than just reporting the first mismatch.

Signed-off-by: Randolph Sapp <rs@ti.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
lib/efi_selftest/efi_selftest_memory.c

index 4d32a28006136d3a4ba364fe32aa78f596d991d0..7320964c129e93d8f873255ac268bde08b34a8bc 100644 (file)
@@ -60,7 +60,7 @@ static int find_in_memory_map(efi_uintn_t map_size,
                              u64 addr, int memory_type)
 {
        efi_uintn_t i;
-       bool found = false;
+       struct efi_mem_desc *match = NULL;
 
        for (i = 0; map_size; ++i, map_size -= desc_size) {
                struct efi_mem_desc *entry = &memory_map[i];
@@ -72,24 +72,23 @@ static int find_in_memory_map(efi_uintn_t map_size,
 
                if (addr >= entry->physical_start &&
                    addr < entry->physical_start +
-                           (entry->num_pages << EFI_PAGE_SHIFT)) {
-                       if (found) {
+                                   (entry->num_pages << EFI_PAGE_SHIFT)) {
+                       if (match) {
                                efi_st_error("Duplicate memory map entry\n");
                                return EFI_ST_FAILURE;
                        }
-                       found = true;
-                       if (memory_type != entry->type) {
-                               efi_st_error
-                                       ("Wrong memory type %d, expected %d\n",
-                                        entry->type, memory_type);
-                               return EFI_ST_FAILURE;
-                       }
+                       match = entry;
                }
        }
-       if (!found) {
+       if (!match) {
                efi_st_error("Missing memory map entry\n");
                return EFI_ST_FAILURE;
        }
+       if (memory_type != match->type) {
+               efi_st_error("Wrong memory type %d, expected %d\n", match->type,
+                            memory_type);
+               return EFI_ST_FAILURE;
+       }
        return EFI_ST_SUCCESS;
 }