From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] FIT: refactor compression handling into separate function
Date: Fri, 25 Aug 2023 12:22:45 +0200 [thread overview]
Message-ID: <20230825102246.4189465-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2023-08-25 10:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-25 10:22 Ahmad Fatoum [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230825102246.4189465-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox