[PATCH 1/2] FIT: refactor compression handling into separate function
Sascha Hauer
sha at pengutronix.de
Mon Aug 28 00:52:23 PDT 2023
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 at 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 |
More information about the barebox
mailing list