From 28980318032ea19031f0a739221e24f1ad87a09c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 29 Apr 2026 17:40:00 +0200 Subject: efi_loader: initialize variables in efi_dp_from_http() When using lwIP, efi_dp_from_http() may fail to initialize ip or mask. Initialize the variables before the call. Addresses-Coverity-ID: 645840 - Uninitialized variables (UNINIT) Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index b3fb20b2501..9efb158f5dd 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -955,8 +955,8 @@ struct efi_device_path *efi_dp_from_http(const char *server, struct udevice *dev efi_uintn_t uridp_len; char *pos; char tmp[128]; - struct efi_ipv4_address ip; - struct efi_ipv4_address mask; + struct efi_ipv4_address ip = { .ip_addr = { 0, 0, 0, 0 } }; + struct efi_ipv4_address mask = { .ip_addr = { 0, 0, 0, 0 } }; if ((server && strlen("http://") + strlen(server) + 1 > sizeof(tmp)) || (!server && IS_ENABLED(CONFIG_NET_LWIP))) -- cgit v1.3.1 From 3ad3243f8a062c0a14adcb645c83f45b55eaeab9 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Wed, 22 Apr 2026 12:09:43 -0500 Subject: efi_dt_fixup: use fdtdec_get_bool Use the more straightforward fdtdec_get_bool instead of fdt_getprop and a return code check. Signed-off-by: Randolph Sapp Reviewed-by: Ilias Apalodimas Reviewed-by: Anshul Dalal Reviewed-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- lib/efi_loader/efi_dt_fixup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 544e1aa9808..333711b9957 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -123,8 +123,7 @@ void efi_carve_out_dt_rsv(void *fdt) fdtdec_get_is_enabled(fdt, subnode)) { bool nomap; - nomap = !!fdt_getprop(fdt, subnode, "no-map", - NULL); + nomap = fdtdec_get_bool(fdt, subnode, "no-map"); efi_reserve_memory(fdt_addr, fdt_size, nomap); } subnode = fdt_next_subnode(fdt, subnode); -- cgit v1.3.1 From 025c4cbd422ccc591595dc321277234fdeb3a967 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Wed, 22 Apr 2026 12:09:44 -0500 Subject: efi_selftest_memory: check for duplicates first 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 Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- lib/efi_selftest/efi_selftest_memory.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/efi_selftest/efi_selftest_memory.c b/lib/efi_selftest/efi_selftest_memory.c index 4d32a280061..7320964c129 100644 --- a/lib/efi_selftest/efi_selftest_memory.c +++ b/lib/efi_selftest/efi_selftest_memory.c @@ -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; } -- cgit v1.3.1 From b1c28ad5fafd95c183b26165e498354db41b755b Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Wed, 22 Apr 2026 12:09:45 -0500 Subject: efi_mem_sort: use list_for_each_entry_safe instead Use list_for_each_entry_safe and comparisons against the current and next efi_mem_desc. This reduces the computation required for merging regions, prevents unnecessary additional iterations of the list, and requires less temporary values. Signed-off-by: Randolph Sapp Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- lib/efi_loader/efi_memory.c | 47 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index b77c2f980cc..046a2bb4641 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -128,44 +128,29 @@ static uint64_t desc_get_end(struct efi_mem_desc *desc) */ static void efi_mem_sort(void) { - struct efi_mem_list *lmem; - struct efi_mem_list *prevmem = NULL; - bool merge_again = true; + struct efi_mem_list *curmem, *nextmem = NULL; list_sort(NULL, &efi_mem, efi_mem_cmp); /* Now merge entries that can be merged */ - while (merge_again) { - merge_again = false; - list_for_each_entry(lmem, &efi_mem, link) { - struct efi_mem_desc *prev; - struct efi_mem_desc *cur; - uint64_t pages; + list_for_each_entry_safe(curmem, nextmem, &efi_mem, link) { + struct efi_mem_desc *cur; + struct efi_mem_desc *next; - if (!prevmem) { - prevmem = lmem; - continue; - } + /* Exit when we've got nothing to compare with */ + if (&nextmem->link == &efi_mem) + break; - cur = &lmem->desc; - prev = &prevmem->desc; - - if ((desc_get_end(cur) == prev->physical_start) && - (prev->type == cur->type) && - (prev->attribute == cur->attribute)) { - /* There is an existing map before, reuse it */ - pages = cur->num_pages; - prev->num_pages += pages; - prev->physical_start -= pages << EFI_PAGE_SHIFT; - prev->virtual_start -= pages << EFI_PAGE_SHIFT; - list_del(&lmem->link); - free(lmem); - - merge_again = true; - break; - } + cur = &curmem->desc; + next = &nextmem->desc; - prevmem = lmem; + if ((cur->physical_start == desc_get_end(next)) && + (cur->type == next->type) && + (cur->attribute == next->attribute)) { + /* There is another similar map coming up, reuse it */ + next->num_pages += cur->num_pages; + list_del(&curmem->link); + free(curmem); } } } -- cgit v1.3.1