[PATCH v5 5/9] efi: Drop the memset() from efi_alloc()

Simon Glass sjg at chromium.org
Sun Dec 1 16:28:07 CET 2024


>From my inspection none of the users need the memory to be zeroed. It
is somewhat unexpected that it does so, since the name gives no clue to
this.

Drop the memset() so that it effectively becomes a wrapper around the
normal EFI-pool allocator.

Another option would be to drop this function and call
efi_allocate_pool() directly, but that increase code size a little.

Move the function comment to the header file like most other exported
functions in U-Boot.

Comments were made in v3 that another project uses memset() when
allocating memory, but that is not required by the spec. In any case, as
above, from inspection, none of the users need the memory to be zeroed,
as they fill the entire region with their own data.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v4)

Changes in v4:
- Expand the commit message

Changes in v3:
- Add new patch to drop the memset() from efi_alloc()
- Drop patch to convert device_path allocation to use malloc()

 include/efi_loader.h        | 2 +-
 lib/efi_loader/efi_memory.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index a67d3827812..a0af0db6262 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -762,7 +762,7 @@ efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf,
 /**
  * efi_alloc() - allocate boot-services-data pool-memory
  *
- * Allocate memory from pool and zero it out.
+ * Allocate memory from pool with type EFI_BOOT_SERVICES_DATA
  *
  * @len:	number of bytes to allocate
  * Return:	pointer to allocated memory or NULL
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index d77243e54b2..76cf908c2de 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -639,7 +639,6 @@ void *efi_alloc(size_t size)
 		log_err("out of memory\n");
 		return NULL;
 	}
-	memset(buf, 0, size);
 
 	return buf;
 }
-- 
2.43.0



More information about the U-Boot mailing list