* [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
* Re: [PATCH] efi: fix memory leak in efi_mem_reserve_iomem()
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
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-12-05 19:20 UTC (permalink / raw)
To: João Guilherme da Silva Freitas Lima, linux-efi, Ard Biesheuvel
Cc: LKML, kernel-janitors
> 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.
Please refine such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.4-rc5#n94
How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.4-rc5#n145
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v7.4-rc5#n34
…
+++ b/drivers/firmware/efi/efi.c
…
> @@ -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) {
…
I suggest to omit a blank line at this source code place.
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] efi: fix memory leak in efi_mem_reserve_iomem()
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
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-12-06 8:36 UTC (permalink / raw)
To: João Guilherme da Silva Freitas Lima, linux-efi, Ard Biesheuvel
Cc: LKML, kernel-janitors
> Hi efi subsystem,
Please take another look at information for the canonical patch format.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.4-rc5#n640
Greetings are probably not needed there.
> 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.
Would an imperative wording approach be preferred for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.4-rc5#n94
Would you like to add error detection and the corresponding exception handling
according to a failed request_resource() call in another function implementation?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.4-rc5#n526
Regards,
Markus
^ 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®