[PATCH 1/4] arm64: Cleanup _probe() return values

Jeremy Linton jeremy.linton at arm.com
Thu May 4 09:41:44 PDT 2023


The decision to process a compressed image should
be part of the image specific detection logic. As such
lets clarify the return logic, and remove the is_zlib_file()
logic in the main file type detection loop.

Signed-off-by: Jeremy Linton <jeremy.linton at arm.com>
---
 kexec/arch/arm64/kexec-arm64.c     |  6 ++++++
 kexec/arch/arm64/kexec-elf-arm64.c |  1 +
 kexec/kexec.c                      | 11 ++++-------
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c
index ec6df4b..a36c103 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/kexec/arch/arm64/kexec-arm64.c
@@ -70,6 +70,12 @@ const struct arch_map_entry arches[] = {
 	{ NULL, 0 },
 };
 
+/*
+ * All arm probe routines must return:
+ * -1 for invalid image
+ * 0 valid image in buffer
+ * >0 fd of valid image after decompression
+ */
 struct file_type file_type[] = {
 	{"vmlinux", elf_arm64_probe, elf_arm64_load, elf_arm64_usage},
 	{"Image", image_arm64_probe, image_arm64_load, image_arm64_usage},
diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c
index e14f8e9..3b7e391 100644
--- a/kexec/arch/arm64/kexec-elf-arm64.c
+++ b/kexec/arch/arm64/kexec-elf-arm64.c
@@ -25,6 +25,7 @@ int elf_arm64_probe(const char *kernel_buf, off_t kernel_size)
 
 	if (result < 0) {
 		dbgprintf("%s: Not an ELF executable.\n", __func__);
+		result = -1;
 		goto on_exit;
 	}
 
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 36bb2ad..97b7226 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -1303,14 +1303,11 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
 	for (i = 0; i < file_types; i++) {
 #ifdef __aarch64__
 		/* handle Image.gz like cases */
-		if (is_zlib_file(kernel, &kernel_size)) {
-			if ((ret = file_type[i].probe(kernel, kernel_size)) >= 0) {
+		if ((ret = file_type[i].probe(kernel_buf, kernel_size)) >= 0) {
+			if (ret > 0)
 				kernel_fd = ret;
-				break;
-			}
-		} else
-			if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
-				break;
+			break;
+		}
 #else
 		if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
 			break;
-- 
2.40.0




More information about the kexec mailing list