Skip to contentSkip to conversation

hw/arm/boot: Explain why load_elf_hdr() error is ignored

PATCH Applied Philippe Mathieu-Daudé 2 participants 2 messages Sep 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/boot: Explain why load_elf_hdr() error is ignored

If the file is not an ELF file, arm_setup_direct_kernel_boot() falls back to try it as a uimage or an AArch64 Image file or as last resort a bare raw binary. We can discard load_elf_hdr() error and silently return.

---
 hw/arm/boot.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/boot.c +6 -2
index d480a7da02..45d0c6b9f2 100644
@@ -799,14 +799,18 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
     } elf_header;
     int data_swab = 0;
     bool big_endian;
-    ssize_t ret = -1;
+    ssize_t ret;
     Error *err = NULL;
 
 
     load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, &err);
     if (err) {
+        /*
+         * If the file is not an ELF file we silently return.
+         * The caller will fall back to try other formats.
+         */
         error_free(err);
-        return ret;
+        return -1;
     }
 
     if (elf_is64) {
Signature · 1 line
2.45.2
#1 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé

If the file is not an ELF file, arm_setup_direct_kernel_boot() falls back to try it as a uimage or an AArch64 Image file or as last resort a bare raw binary. We can discard load_elf_hdr() error and silently return.

---

Applied to target-arm.next, thanks.

-- PMM