summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_memory.c
diff options
context:
space:
mode:
authorSughosh Ganu <sughosh.ganu@linaro.org>2024-07-30 16:41:30 +0530
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2024-07-31 09:54:42 +0200
commit7aa0addc42ef1674a7baaf9d0428db943c3f2e5f (patch)
treedab29b9a140a2e8687e12b1ce3689146a8c2361f /lib/efi_loader/efi_memory.c
parent22f893047db9560400415316256959ed29167d04 (diff)
efi_memory: avoid possible null pointer dereference
Populate the previous memory descriptor node pointer only after it's parent struct has been initialised. The compiler fixes this logic to do the right thing, but it is better to have correct code in place. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib/efi_loader/efi_memory.c')
-rw-r--r--lib/efi_loader/efi_memory.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 9a62864a002..6c5cc26ae38 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -138,7 +138,7 @@ static void efi_mem_sort(void)
merge_again = false;
list_for_each(lhandle, &efi_mem) {
struct efi_mem_list *lmem;
- struct efi_mem_desc *prev = &prevmem->desc;
+ struct efi_mem_desc *prev;
struct efi_mem_desc *cur;
uint64_t pages;
@@ -149,6 +149,7 @@ static void efi_mem_sort(void)
}
cur = &lmem->desc;
+ prev = &prevmem->desc;
if ((desc_get_end(cur) == prev->physical_start) &&
(prev->type == cur->type) &&