ofnode: NULL check bootscr_flash_size before dereference
PATCH v2 1/1 ofnode: NULL check bootscr_flash_size before dereference
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.
---
Changes in v2:
- Refactor to coalesce duplicate assignments of *bootscr_flash_offset
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/core/ofnode.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/core/ofnode.c +6 -6
@@ -1961,6 +1961,12 @@ int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,ofnode uboot; *bootscr_flash_offset =0 ; + +if (!bootscr_flash_size) { +dm_warn ("bootscr-flash-size is zero. Ignoring properties!\n" ); +return -EINVAL ; + } + *bootscr_flash_size =0 ; uboot =ofnode_path ("/options/u-boot" );
@@ -1979,12 +1985,6 @@ int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,if (ret)return -EINVAL ; -if (!bootscr_flash_size) { -dm_warn ("bootscr-flash-size is zero. Ignoring properties!\n" ); - *bootscr_flash_offset =0 ; -return -EINVAL ; - } -return 0 ; }
---
base-commit: 7027b445cc0bfb86204ecb1f1fe596f5895048d9
change-id: 20250703-ofnode_fix-284e601e4329
Best regards,
Signature · 1 line
Andrew Goodbody <[email protected]>
Quoted 6 lines · Andrew Goodbody
Move the NULL check of
bootscr_flash_sizeto before the first time it is dereferenced to avoid any possible segment violations.This issue found by Smatch.
Signed-off-by Andrew Goodbody <[email protected]>
Signature · 1 line
Tom
Quoted 6 lines · Andrew Goodbody
Move the NULL check of
bootscr_flash_sizeto before the first time it is dereferenced to avoid any possible segment violations.This issue found by Smatch.
Applied to u-boot/master, thanks!
[1/1] ofnode: NULL check bootscr_flash_size before dereference
commit: cd79a2839b01571b6f2915c219f71c05e3c97482
Signature · 1 line
Tom