[PATCH 4/6] efi: Avoid pool allocation in efi_get_memory_map_alloc()

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Jul 25 18:38:15 CEST 2024


On 25.07.24 15:56, Simon Glass wrote:
> This function returns the memory map, allocating memory for it. But it
> can just use malloc() directly, rather than calling the pool allocator.
> Update it.

The size of the memory map may exceed CONFIG_SYS_MALLOC_LEN which tends
to be astonishingly small: 1 MiB or less on many boards.

Best regards

Heinrich

>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
>   lib/efi_loader/efi_memory.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> index 087f4c88cdf..2945f5648c7 100644
> --- a/lib/efi_loader/efi_memory.c
> +++ b/lib/efi_loader/efi_memory.c
> @@ -850,14 +850,13 @@ efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size,
>   	ret = efi_get_memory_map(map_size, *memory_map, NULL, NULL, NULL);
>   	if (ret == EFI_BUFFER_TOO_SMALL) {
>   		*map_size += sizeof(struct efi_mem_desc); /* for the map */
> -		ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, *map_size,
> -					(void **)memory_map);
> -		if (ret != EFI_SUCCESS)
> -			return ret;
> +		*memory_map = malloc(*map_size);
> +		if (!*memory_map)
> +			return EFI_OUT_OF_RESOURCES;
>   		ret = efi_get_memory_map(map_size, *memory_map,
>   					 NULL, NULL, NULL);
>   		if (ret != EFI_SUCCESS) {
> -			efi_free_pool(*memory_map);
> +			free(*memory_map);
>   			*memory_map = NULL;
>   		}
>   	}



More information about the U-Boot mailing list