[PATCH master 11/39] efi: loader: fix multiple bugs in efi_loader_bootm
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Feb 16 00:44:11 PST 2026
Fix several issues:
- ERR_PTR(-efi_errno(ret)) uses 'ret' which is 0 at that point
instead of 'efiret' which holds the actual error.
- Two return statements (PTR_ERR(fdt) and efi_install_fdt error)
bypass the 'out:' cleanup label, leaking file_path, load_option,
and the source sdram region. Replace with goto out.
- efi_set_watchdog() and __efi_start_image() return efi_status_t
(unsigned long, 64-bit on ARM64) but were stored in 'int ret',
truncating the value. Use 'efiret' for these calls. Also fix the
success return path to convert efiret properly.
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
efi/loader/bootm.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/efi/loader/bootm.c b/efi/loader/bootm.c
index da664847def8..a74002e292f7 100644
--- a/efi/loader/bootm.c
+++ b/efi/loader/bootm.c
@@ -233,19 +233,21 @@ static int efi_loader_bootm(struct image_data *data)
efiret = efi_init_obj_list();
if (efiret) {
pr_err("Cannot initialize UEFI sub-system: %pe\n",
- ERR_PTR(-efi_errno(ret)));
+ ERR_PTR(-efi_errno(efiret)));
goto out;
}
ret = -EINVAL;
fdt = bootm_get_devicetree(data);
- if (IS_ERR(fdt))
- return PTR_ERR(fdt);
+ if (IS_ERR(fdt)) {
+ ret = PTR_ERR(fdt);
+ goto out;
+ }
if (fdt) {
ret = efi_install_fdt(fdt);
if (ret)
- return ret;
+ goto out;
}
efiret = efi_install_initrd(data, source);
@@ -280,17 +282,17 @@ static int efi_loader_bootm(struct image_data *data)
* Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A
* 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer
*/
- ret = efi_set_watchdog(300);
- if (ret != EFI_SUCCESS) {
+ efiret = efi_set_watchdog(300);
+ if (efiret != EFI_SUCCESS) {
pr_err("failed to set watchdog timer\n");
goto out;
}
/* Call our payload! */
- ret = __efi_start_image(handle, &exit_data_size, &exit_data, flags);
- if (ret != EFI_SUCCESS) {
+ efiret = __efi_start_image(handle, &exit_data_size, &exit_data, flags);
+ if (efiret != EFI_SUCCESS) {
pr_err("## Application failed, r = %lu\n",
- ret & ~EFI_ERROR_MASK);
+ efiret & ~EFI_ERROR_MASK);
if (exit_data) {
pr_err("## %ls\n", exit_data);
efi_free_pool(exit_data);
@@ -311,7 +313,7 @@ static int efi_loader_bootm(struct image_data *data)
/* Control is returned to us, disable EFI watchdog */
efi_set_watchdog(0);
- return ret;
+ return -efi_errno(efiret);
out:
efi_initrd_unregister();
--
2.47.3
More information about the barebox
mailing list