diff mbox series

efi_loader: Simplify efi_free_pages()

Message ID 20241024110156.1353756-1-ilias.apalodimas@linaro.org
State Accepted
Commit 4588ab997634a73ac2ac6b47ce8009152f59cace
Headers show
Series efi_loader: Simplify efi_free_pages() | expand

Commit Message

Ilias Apalodimas Oct. 24, 2024, 11:01 a.m. UTC
We currently call efi_free_pages() with a notify flag and explicitly
update the efi memory map. That's not needed as lmb_free_flags() will do
that for us if the LMB_NONOTIFY flag is removed

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 lib/efi_loader/efi_memory.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Heinrich Schuchardt Oct. 28, 2024, 6:23 a.m. UTC | #1
On 10/24/24 13:01, Ilias Apalodimas wrote:
> We currently call efi_free_pages() with a notify flag and explicitly
> update the efi memory map. That's not needed as lmb_free_flags() will do
> that for us if the LMB_NONOTIFY flag is removed
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

> ---
>   lib/efi_loader/efi_memory.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> index 84be5532a655..e493934c7131 100644
> --- a/lib/efi_loader/efi_memory.c
> +++ b/lib/efi_loader/efi_memory.c
> @@ -524,7 +524,6 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type,
>   efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages)
>   {
>   	u64 len;
> -	uint flags;
>   	long status;
>   	efi_status_t ret;
>
> @@ -539,18 +538,17 @@ efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages)
>   		return EFI_INVALID_PARAMETER;
>   	}
>
> -	flags = LMB_NOOVERWRITE | LMB_NONOTIFY;
>   	len = (u64)pages << EFI_PAGE_SHIFT;
> +	/*
> +	 * The 'memory' variable for sandbox holds a pointer which has already
> +	 * been mapped with map_sysmem() from efi_allocate_pages(). Convert
> +	 * it back to an address LMB understands
> +	 */
>   	status = lmb_free_flags(map_to_sysmem((void *)(uintptr_t)memory), len,
> -				flags);
> +				LMB_NOOVERWRITE);
>   	if (status)
>   		return EFI_NOT_FOUND;
>
> -	ret = efi_add_memory_map_pg(memory, pages, EFI_CONVENTIONAL_MEMORY,
> -				    false);
> -	if (ret != EFI_SUCCESS)
> -		return EFI_NOT_FOUND;
> -
>   	unmap_sysmem((void *)(uintptr_t)memory);
>
>   	return ret;
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 84be5532a655..e493934c7131 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -524,7 +524,6 @@  efi_status_t efi_allocate_pages(enum efi_allocate_type type,
 efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages)
 {
 	u64 len;
-	uint flags;
 	long status;
 	efi_status_t ret;
 
@@ -539,18 +538,17 @@  efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages)
 		return EFI_INVALID_PARAMETER;
 	}
 
-	flags = LMB_NOOVERWRITE | LMB_NONOTIFY;
 	len = (u64)pages << EFI_PAGE_SHIFT;
+	/*
+	 * The 'memory' variable for sandbox holds a pointer which has already
+	 * been mapped with map_sysmem() from efi_allocate_pages(). Convert
+	 * it back to an address LMB understands
+	 */
 	status = lmb_free_flags(map_to_sysmem((void *)(uintptr_t)memory), len,
-				flags);
+				LMB_NOOVERWRITE);
 	if (status)
 		return EFI_NOT_FOUND;
 
-	ret = efi_add_memory_map_pg(memory, pages, EFI_CONVENTIONAL_MEMORY,
-				    false);
-	if (ret != EFI_SUCCESS)
-		return EFI_NOT_FOUND;
-
 	unmap_sysmem((void *)(uintptr_t)memory);
 
 	return ret;