From: dev12124 <joaoanandalima@gmail.com>
To: ardb@kernel.org
Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
"João Guilherme da Silva Freitas Lima" <joaoanandalima@gmail.com>
Subject: [PATCH] efi: fix memory leak in efi_mem_reserve_iomem()
Date: Sat, 5 Dec 2026 15:47:40 -0300 [thread overview]
Message-ID: <20261205184743.1195-1-joaoanandalima@gmail.com> (raw)
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
--
next reply other threads:[~2026-12-05 18:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 18:47 dev12124 [this message]
2026-12-05 19:20 ` Markus Elfring
2026-12-06 8:36 ` Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205184743.1195-1-joaoanandalima@gmail.com \
--to=joaoanandalima@gmail.com \
--cc=ardb@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®