common/spl: improve error handling in spl_fit
authorMikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Tue, 10 Jun 2025 09:56:32 +0000 (12:56 +0300)
committerTom Rini <trini@konsulko.com>
Thu, 19 Jun 2025 17:01:51 +0000 (11:01 -0600)
commit8bb9c275c484206c0314014d8215770aaac4cefe
tree0f6ace9a9b14066046aeb03900542df6d0084f49
parent3eb43c54fadba457f22e415a2821145164efe662
common/spl: improve error handling in spl_fit

This fix a possible NULL pointer dereference.

There is also a risk of memory leaking within the same portion of code.
The leak will happen if loaded image is bad or damaged. In this case
u-boot-spl will try booting from the other available media. Unfortunately
resources allocated for previous boot media will NOT be freed.

We can't fix that issue as the memory allocation mechanism used here
is unknown. It can be different kinds of malloc() or something else.

To somewhat reduce memory consumption, one can try to reuse previously
allocated memory as it's done in board_spl_fit_buffer_addr() from
test/image/spl_load.c.

The corresponding comment was put to the code as well.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Reviewed-by: Anshul Dalal <anshuld@ti.com>
common/spl/spl_fit.c