mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] FIT: refactor compression handling into separate function
@ 2023-08-25 10:22 Ahmad Fatoum
  2023-08-25 10:22 ` [PATCH 2/2] FIT: do not decompress ramdisks even if asked Ahmad Fatoum
  2023-08-28  7:52 ` [PATCH 1/2] FIT: refactor compression handling into separate function Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-08-25 10:22 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

There are four conditions that need to be true for successful decompression
and the follow-up commit will add one more. Thus split off the compression
handling to aid readability.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/image-fit.c | 62 ++++++++++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index af9b2a94793c..9ceebde02931 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -564,6 +564,40 @@ static void fit_uncompress_error_fn(char *x)
 	pr_err("%s\n", x);
 }
 
+static int fit_handle_decompression(struct device_node *image,
+				    const void **data,
+				    int *data_len)
+{
+	const char *compression = NULL;
+	void *uc_data;
+	int ret;
+
+	of_property_read_string(image, "compression", &compression);
+	if (!compression || !strcmp(compression, "none"))
+		return 0;
+
+	if (!IS_ENABLED(CONFIG_UNCOMPRESS)) {
+		pr_err("image has compression = \"%s\", but support not compiled in\n",
+		       compression);
+		return -ENOSYS;
+	}
+
+	ret = uncompress_buf_to_buf(*data, *data_len, &uc_data,
+				    fit_uncompress_error_fn);
+	if (ret < 0) {
+		pr_err("data couldn't be decompressed\n");
+		return ret;
+	}
+
+	*data = uc_data;
+	*data_len = ret;
+
+	/* associate buffer with FIT, so it's not leaked */
+	__of_new_property(image, "uncompressed-data", uc_data, *data_len);
+
+	return 0;
+}
+
 /**
  * fit_open_image - Open an image in a FIT image
  * @handle: The FIT image handle
@@ -586,8 +620,7 @@ int fit_open_image(struct fit_handle *handle, void *configuration,
 		   unsigned long *outsize)
 {
 	struct device_node *image;
-	const char *unit = name, *type = NULL, *compression = NULL,
-	      *desc= "(no description)";
+	const char *unit = name, *type = NULL, *desc= "(no description)";
 	const void *data;
 	int data_len;
 	int ret = 0;
@@ -619,28 +652,9 @@ int fit_open_image(struct fit_handle *handle, void *configuration,
 	if (ret < 0)
 		return ret;
 
-	of_property_read_string(image, "compression", &compression);
-	if (compression && strcmp(compression, "none") != 0) {
-		void *uc_data;
-
-		if (!IS_ENABLED(CONFIG_UNCOMPRESS)) {
-			pr_err("image has compression = \"%s\", but support not compiled in\n",
-			       compression);
-			return -ENOSYS;
-		}
-
-		data_len = uncompress_buf_to_buf(data, data_len, &uc_data,
-					    fit_uncompress_error_fn);
-		if (data_len < 0) {
-			pr_err("data couldn't be decompressed\n");
-			return data_len;
-		}
-
-		data = uc_data;
-
-		/* associate buffer with FIT, so it's not leaked */
-		__of_new_property(image, "uncompressed-data", uc_data, data_len);
-	}
+	ret = fit_handle_decompression(image, &data, &data_len);
+	if (ret)
+		return ret;
 
 	*outdata = data;
 	*outsize = data_len;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-28  7:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-25 10:22 [PATCH 1/2] FIT: refactor compression handling into separate function Ahmad Fatoum
2023-08-25 10:22 ` [PATCH 2/2] FIT: do not decompress ramdisks even if asked Ahmad Fatoum
2023-08-25 10:45   ` Christian Eggers
2023-08-28  7:52 ` [PATCH 1/2] FIT: refactor compression handling into separate function Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox