From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] FIT: refactor compression handling into separate function
Date: Mon, 28 Aug 2023 09:52:23 +0200 [thread overview]
Message-ID: <20230828075223.GI16522@pengutronix.de> (raw)
In-Reply-To: <20230825102246.4189465-1-a.fatoum@pengutronix.de>
On Fri, Aug 25, 2023 at 12:22:45PM +0200, Ahmad Fatoum wrote:
> 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(-)
Applied, thanks
Sascha
>
> 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
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2023-08-28 7:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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-25 10:45 ` Christian Eggers
2023-08-28 7:52 ` Sascha Hauer [this message]
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=20230828075223.GI16522@pengutronix.de \
--to=sha@pengutronix.de \
--cc=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