[U-Boot] [PATCH 12/14] tools: Correct error handling in fit_image_process_hash()

Teddy Reed
2016-07-03T21:16:42Z

Hi Simon,

On Sun, Jul 3, 2016 at 8:40 AM, Simon Glass <sjg@chromium.org> wrote:
> We should not be returning -1 as an error code. This can mask a situation
> where we run out of space adding things to the FIT. By returning the correct
> error in this case (-ENOSPC) it can be handled by the higher-level code.
>
> This may fix the error reported by Tom Van Deun here:
>
> https://www.mail-archive.com/u-boot at lists.denx.de/msg217417.html
>
> although I am not sure as I cannot actually repeat it.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reported-by: Tom Van Deun <tom.vandeun@wapice.com>

Reviewed-by: Teddy Reed <teddy.reed@gmail.com>

> ---
>
> tools/image-host.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/tools/image-host.c b/tools/image-host.c
> index 7effb6c..3e14fdc 100644
> --- a/tools/image-host.c
> +++ b/tools/image-host.c
> @@ -38,7 +38,7 @@ static int fit_set_hash_value(void *fit, int noffset, uint8_t *value,
> printf("Can't set hash '%s' property for '%s' node(%s)\n",
> FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL),
> fdt_strerror(ret));
> - return -1;
> + return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
> }
>
> return 0;
> @@ -64,25 +64,27 @@ static int fit_image_process_hash(void *fit, const char *image_name,
> const char *node_name;
> int value_len;
> char *algo;
> + int ret;
>
> node_name = fit_get_name(fit, noffset, NULL);
>
> if (fit_image_hash_get_algo(fit, noffset, &algo)) {
> printf("Can't get hash algo property for '%s' hash node in '%s' image node\n",
> node_name, image_name);
> - return -1;
> + return -ENOENT;
> }
>
> if (calculate_hash(data, size, algo, value, &value_len)) {
> printf("Unsupported hash algorithm (%s) for '%s' hash node in '%s' image node\n",
> algo, node_name, image_name);
> - return -1;
> + return -EPROTONOSUPPORT;
> }
>
> - if (fit_set_hash_value(fit, noffset, value, value_len)) {
> + ret = fit_set_hash_value(fit, noffset, value, value_len);
> + if (ret) {
> printf("Can't set hash value for '%s' hash node in '%s' image node\n",
> node_name, image_name);
> - return -1;
> + return ret;
> }
>
> return 0;
> @@ -322,7 +324,7 @@ int fit_image_add_verification_data(const char *keydir, void *keydest,
> comment, require_keys);
> }
> if (ret)
> - return -1;
> + return ret;
> }
>
> return 0;
> --
> 2.8.0.rc3.226.g39d4020
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot

--
Teddy Reed V