From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Date: Sun, 30 Jul 2023 10:36:17 +0000 (+0200)
Subject: efi_loader: out of memory in efi_add_memory_map_pg
X-Git-Tag: v2025.01-rc5-pxa1908~902^2~7
X-Git-Url: http://git.dujemihanovic.xyz/img/html/static/%7B%7B%20.Permalink%20%7D%7D?a=commitdiff_plain;h=ba27563093f4398ebf38e1e505fe50a00a5e17e7;p=u-boot.git

efi_loader: out of memory in efi_add_memory_map_pg

Handle out of memory situation in efi_add_memory_map_pg().

Fixes: 5d00995c361c ("efi_loader: Implement memory allocation and map")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index e2ca78d935..2c5d5221a7 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -282,6 +282,8 @@ static efi_status_t efi_add_memory_map_pg(u64 start, u64 pages,
 
 	++efi_memory_map_key;
 	newlist = calloc(1, sizeof(*newlist));
+	if (!newlist)
+		return EFI_OUT_OF_RESOURCES;
 	newlist->desc.type = memory_type;
 	newlist->desc.physical_start = start;
 	newlist->desc.virtual_start = start;