allocate_pool has to return a buffer which is 8-byte aligned. Shift the
region returned by allocate_pages by 8 byte and store the size in the
headroom. The 8 byte overhead is neglegible, but provides the required
size when freeing the allocation later.

Signed-off-by: Stefan Brüns <stefan.bru...@rwth-aachen.de>
---
 lib/efi_loader/efi_boottime.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index be6f5e8..3e526eb 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -134,18 +134,35 @@ static efi_status_t EFIAPI efi_allocate_pool(int 
pool_type, unsigned long size,
                                             void **buffer)
 {
        efi_status_t r;
+       u64 num_pages = (size + 8 + 0xfff) >> 12;
 
        EFI_ENTRY("%d, %ld, %p", pool_type, size, buffer);
-       r = efi_allocate_pages(0, pool_type, (size + 0xfff) >> 12, 
(void*)buffer);
+
+       if (size == 0) {
+               *buffer = NULL;
+               return EFI_EXIT(EFI_SUCCESS);
+       }
+
+       r = efi_allocate_pages(0, pool_type, num_pages, (void *)buffer);
+       if (r == EFI_SUCCESS) {
+               *(u64 *)(*buffer) = num_pages;
+               *buffer = (char *)(*buffer) + 8;
+       }
+
        return EFI_EXIT(r);
 }
 
 static efi_status_t EFIAPI efi_free_pool(void *buffer)
 {
        efi_status_t r;
+       u64 num_pages;
 
        EFI_ENTRY("%p", buffer);
-       r = efi_free_pages((ulong)buffer, 0);
+
+       buffer = (char *)(buffer) - 8;
+       num_pages = *(u64 *)buffer;
+
+       r = efi_free_pages((ulong)buffer, num_pages);
        return EFI_EXIT(r);
 }
 
-- 
2.10.0

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to