diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2023-07-30 12:27:03 +0200 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2023-08-03 09:21:02 +0200 |
commit | 257a498fbb146f866d729176a6fce5875323d4b9 (patch) | |
tree | 20401b3a4cb61e02d27abda3cb6534d113927a18 /lib/efi_loader/efi_memory.c | |
parent | 48d183f2acb0157856254f52d2d856a07463acd4 (diff) |
efi_loader: out of memory in efi_mem_carve_out
Handle out of memory situation in efi_mem_carve_out().
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>
Diffstat (limited to 'lib/efi_loader/efi_memory.c')
-rw-r--r-- | lib/efi_loader/efi_memory.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 4630387af02..45d3bf52b8a 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -34,6 +34,7 @@ struct efi_mem_list { #define EFI_CARVE_NO_OVERLAP -1 #define EFI_CARVE_LOOP_AGAIN -2 #define EFI_CARVE_OVERLAPS_NONRAM -3 +#define EFI_CARVE_OUT_OF_RESOURCES -4 /* This list contains all memory map items */ static LIST_HEAD(efi_mem); @@ -239,6 +240,8 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, /* Create a new map from [ carve_start ... map_end ] */ newmap = calloc(1, sizeof(*newmap)); + if (!newmap) + return EFI_CARVE_OUT_OF_RESOURCES; newmap->desc = map->desc; newmap->desc.physical_start = carve_start; newmap->desc.virtual_start = carve_start; @@ -313,6 +316,9 @@ static efi_status_t efi_add_memory_map_pg(u64 start, u64 pages, r = efi_mem_carve_out(lmem, &newlist->desc, overlap_only_ram); switch (r) { + case EFI_CARVE_OUT_OF_RESOURCES: + free(newlist); + return EFI_OUT_OF_RESOURCES; case EFI_CARVE_OVERLAPS_NONRAM: /* * The user requested to only have RAM overlaps, |