]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
ofnode: NULL check bootscr_flash_size before dereference
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Mon, 7 Jul 2025 10:04:29 +0000 (11:04 +0100)
committerTom Rini <trini@konsulko.com>
Mon, 14 Jul 2025 21:16:56 +0000 (15:16 -0600)
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@linaro.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/core/ofnode.c

index 26e014d5c53e4ad52783ad67ac5e7ccd9b1274c5..e040e3f2806ffe74c58dcd82f36307351acd5a99 100644 (file)
@@ -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;
 }