[PATCH] boot/fit: remove useless else branch

Simon Glass sjg at chromium.org
Thu Apr 2 23:02:37 CEST 2026


Hi Julien,

On 2026-03-24T15:33:45, Julien Stephan <jstephan at baylibre.com> wrote:
> boot/fit: remove useless else branch
>
> The assignment of load = data is already performed before the
> if–elseif logic, making the additional assignment in the else
> branch unnecessary.
>
> Remove the redundant statement to simplify
> the control flow and improve readability.
>
> Signed-off-by: Julien Stephan <jstephan at baylibre.com>
> Reviewed-by: Quentin Schulz <quentin.schulz at cherry.de>

> diff --git a/boot/image-fit.c b/boot/image-fit.c
> @@ -2281,8 +2281,6 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
> -     } else {
> -             load = data;    /* No load address specified */
>       }

This else branch is not redundant. When fit_image_get_load() succeeds,
it writes to load, so load contains the value from the FIT image, not
data.

The else branch is reached when load_op == FIT_LOAD_OPTIONAL_NON_ZERO
and !load - here the code intentionally resets load back to data,
meaning 'ignore a zero load address and load in place instead'.

With your patch, load would remain 0, causing problems in the caller
(e.g. the check at line 2316 would see load != data and attempt to
memcpy() to address 0).

The comment "No load address specified" is misleading since we only
reach this branch when the load address WAS specified but was zero. If
you want to clean this up, please update the comment!

It also makes me wonder if we are lacking a test in this area.

Regards,
Simon


More information about the U-Boot mailing list