mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] efi: fix memory leak in efi_mem_reserve_iomem()
@ 2026-12-05 18:47 dev12124
  2026-12-05 19:20 ` Markus Elfring
  2026-12-06  8:36 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: dev12124 @ 2026-12-05 18:47 UTC (permalink / raw)
  To: ardb; +Cc: linux-efi, linux-kernel, João Guilherme da Silva Freitas Lima

From: João Guilherme da Silva Freitas Lima <joaoanandalima@gmail.com>

Hi efi subsystem,

I reading the code of efi.c and, is noted a small memory leak:

In this line:

	ret = parent ? request_resource(parent, res) : 0;

If ret == 0, is success. But, if not is 0 (ret != 0) ?	This patch added a verification 
to this case, removing res for evits a memory leak and return the ret.


Signed-off-by: João Guilherme da Silva Freitas Lima <joaoanandalima@gmail.com>

---
 drivers/firmware/efi/efi.c | 5 +++++
 1 file changed, 5 insertions(+), 0 deletion(-)

Thanks to read this patch!

Cheers, 
	João.

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 355d4cb04..01dcc0bec 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -1101,7 +1101,7 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size)
 	int ret;
 
 	res = kzalloc_obj(struct resource, GFP_ATOMIC);
	if (!res) 
 		return -ENOMEM;
 
 	res->name	= "reserved";
@@ -1113,6 +1113,11 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size)
 	parent = request_resource_conflict(&iomem_resource, res);
 	ret = parent ? request_resource(parent, res) : 0;
 
+	if (ret) {
+		kfree(res);
+		return ret;
+	}
+
 	/*
 	 * Given that efi_mem_reserve_iomem() can be called at any
 	 * time, only call memblock_reserve() if the architecture
-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-06  8:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 18:47 [PATCH] efi: fix memory leak in efi_mem_reserve_iomem() dev12124
2026-12-05 19:20 ` Markus Elfring
2026-12-06  8:36 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®