From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
Chali Anis <chalianis1@gmail.com>
Subject: [PATCH 2/2] efi: payload: bootm: fix potential double-unload for image
Date: Tue, 14 Apr 2026 16:26:30 +0200 [thread overview]
Message-ID: <20260414142634.744542-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260414142634.744542-1-a.fatoum@pengutronix.de>
efi_execute_image() already takes care to unload the image if it returns,
so adapt the single caller that tries to unload the image again
accordingly.
Cc: Chali Anis <chalianis1@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/payload/bootm.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
index aba643b2c59d..801c0202ae83 100644
--- a/efi/payload/bootm.c
+++ b/efi/payload/bootm.c
@@ -235,6 +235,7 @@ static int do_bootm_efi_stub(struct image_data *data)
{
struct efi_loaded_image *loaded_image;
void *fdt = NULL, *initrd = NULL;
+ bool image_freed = false;
efi_handle_t handle;
enum filetype type;
int ret;
@@ -257,6 +258,13 @@ static int do_bootm_efi_stub(struct image_data *data)
goto unload_ramdisk;
ret = efi_execute_image(handle, loaded_image, type);
+
+ /* efi_execute_image takes care to unload the image on error,
+ * so we set image_freed and fall through to freeing ramdisk
+ * and oftree.
+ */
+ image_freed = true;
+
unload_ramdisk:
if (initrd) {
efi_initrd_unregister();
@@ -265,7 +273,8 @@ static int do_bootm_efi_stub(struct image_data *data)
unload_oftree:
efi_unload_fdt(fdt);
unload_os:
- BS->unload_image(handle);
+ if (!image_freed)
+ BS->unload_image(handle);
return ret;
}
--
2.47.3
next prev parent reply other threads:[~2026-04-14 14:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 14:26 [PATCH 1/2] efi: payload: image: exit if kernel image returned Ahmad Fatoum
2026-04-14 14:26 ` Ahmad Fatoum [this message]
2026-04-15 6:29 ` Sascha Hauer
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=20260414142634.744542-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=chalianis1@gmail.com \
/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