* [PATCH v2 1/1] efi_loader: out of memory in efi_mem_carve_out
@ 2023-07-30 10:54 Heinrich Schuchardt
2023-07-31 8:37 ` Ilias Apalodimas
0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2023-07-30 10:54 UTC (permalink / raw)
To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt
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>
---
v2:
non leak newlist
---
lib/efi_loader/efi_memory.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 9de6cf6010..48d641d231 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;
@@ -311,6 +314,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,
--
2.40.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 1/1] efi_loader: out of memory in efi_mem_carve_out
2023-07-30 10:54 [PATCH v2 1/1] efi_loader: out of memory in efi_mem_carve_out Heinrich Schuchardt
@ 2023-07-31 8:37 ` Ilias Apalodimas
0 siblings, 0 replies; 2+ messages in thread
From: Ilias Apalodimas @ 2023-07-31 8:37 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: u-boot
On Sun, 30 Jul 2023 at 13:54, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> 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>
> ---
> v2:
> non leak newlist
> ---
> lib/efi_loader/efi_memory.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> index 9de6cf6010..48d641d231 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;
> @@ -311,6 +314,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,
> --
> 2.40.1
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-31 8:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-30 10:54 [PATCH v2 1/1] efi_loader: out of memory in efi_mem_carve_out Heinrich Schuchardt
2023-07-31 8:37 ` Ilias Apalodimas
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.