[PATCH] ofnode: NULL check bootscr_flash_size before dereference

Tom Rini trini at konsulko.com
Fri Jul 4 23:01:16 CEST 2025


On Thu, Jul 03, 2025 at 05:05:31PM +0100, Andrew Goodbody wrote:

> Move the NULL check of bootscr_flash_size to before the first time it is
> dereferenced to avoid any possible segment violations.
> 
> This issue found by Smatch.
> 
> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
> ---
>  drivers/core/ofnode.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
> index 26e014d5c53..1c285a867b3 100644
> --- a/drivers/core/ofnode.c
> +++ b/drivers/core/ofnode.c
> @@ -1960,6 +1960,12 @@ int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,
>  	int ret;
>  	ofnode uboot;
>  
> +	if (!bootscr_flash_size) {
> +		dm_warn("bootscr-flash-size is zero. Ignoring properties!\n");
> +		*bootscr_flash_offset = 0;
> +		return -EINVAL;
> +	}
> +
>  	*bootscr_flash_offset = 0;
>  	*bootscr_flash_size = 0;

Is the compiler likely to optimize this to:
*bootscr_flash_offset = 0;
if (!bootscr_flash_size) {
  ...dm_warn(...)
  return -EINVAL;
}
*bootscr_flash_size = 0;

Otherwise we should re-organize it like that. And yes, the two patches
today for "fix platform ... because it grew too much" reminded me to be
picky like this.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250704/c4fb94a9/attachment.sig>


More information about the U-Boot mailing list