diff mbox series

[2/2] x86/efi: Fix memory leak for EFI memmap reservations

Message ID 26d637af-480b-e874-ee84-9b2abe43630b@huawei.com (mailing list archive)
State Deferred, archived
Headers show
Series [1/2] efi: Add efi_memmap_free() to free EFI memory map | expand

Commit Message

Yunfeng Ye Sept. 25, 2019, 9:20 a.m. UTC
There are some memory leaks in failure path after efi_memmap_alloc().
add efi_memmap_free() for this situation.

Fixes: 816e76129ed5 ("efi: Allow drivers to reserve boot services forever")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 arch/x86/platform/efi/quirks.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 3b9fd67..a755f35 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -285,6 +285,7 @@  void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size)

 	new = early_memremap(new_phys, new_size);
 	if (!new) {
+		efi_memmap_free(new_phys, num_entries);
 		pr_err("Failed to map new boot services memmap\n");
 		return;
 	}
@@ -470,6 +471,7 @@  void __init efi_free_boot_services(void)

 	new = memremap(new_phys, new_size, MEMREMAP_WB);
 	if (!new) {
+		efi_memmap_free(new_phys, num_entries);
 		pr_err("Failed to map new EFI memmap\n");
 		return;
 	}
@@ -493,6 +495,7 @@  void __init efi_free_boot_services(void)
 	memunmap(new);

 	if (efi_memmap_install(new_phys, num_entries)) {
+		efi_memmap_free(new_phys, num_entries);
 		pr_err("Could not install new EFI memmap\n");
 		return;
 	}