diff mbox series

[2/6] lib/decompress: Introduce decompress_method_by_name()

Message ID 20230306030305.15595-3-kernelfans@gmail.com (mailing list archive)
State New, archived
Headers show
Series arm64: make kexec_file able to load zboot image | expand

Commit Message

Pingfan Liu March 6, 2023, 3:03 a.m. UTC
The zboot image packs the compressed file in the data section. Instead
of starting with the zip file header. It records the compressing method
name 'gzip','lzma' etc in the zboot image header.

Hence it is easier to decide the decompressing method by the name than
by the magic number.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: kexec@lists.infradead.org
To: linux-kernel@vger.kernel.org
---
 include/linux/decompress/generic.h |  2 ++
 lib/decompress.c                   | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/linux/decompress/generic.h b/include/linux/decompress/generic.h
index 207d80138db5..077f15ce77b9 100644
--- a/include/linux/decompress/generic.h
+++ b/include/linux/decompress/generic.h
@@ -37,4 +37,6 @@  typedef int (*decompress_fn) (unsigned char *inbuf, long len,
 decompress_fn decompress_method(const unsigned char *inbuf, long len,
 				const char **name);
 
+decompress_fn decompress_method_by_name(const unsigned char *name);
+
 #endif
diff --git a/lib/decompress.c b/lib/decompress.c
index ab3fc90ffc64..8dd6f87e885f 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -2,7 +2,7 @@ 
 /*
  * decompress.c
  *
- * Detect the decompression method based on magic number
+ * Detect the decompression method based on magic number or name
  */
 
 #include <linux/decompress/generic.h>
@@ -82,3 +82,15 @@  decompress_fn __init decompress_method(const unsigned char *inbuf, long len,
 		*name = cf->name;
 	return cf->decompressor;
 }
+
+decompress_fn __init decompress_method_by_name(const unsigned char *name)
+{
+	const struct compress_format *cf;
+
+	for (cf = compressed_formats; cf->name; cf++) {
+		if (!strcmp(name, cf->name))
+			break;
+
+	}
+	return cf->decompressor;
+}