[PATCH] dm: core: fix no null pointer detection in ofnode_get_addr_size_index()

From: Chen Guanqiao chenguanqiao@kuaishou.com
Fixed a defect of a null pointer being discovered by Coverity Scan: CID 331544: Null pointer dereferences (REVERSE_INULL) Null-checking "size" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
Signed-off-by: Chen Guanqiao chenguanqiao@kuaishou.com --- drivers/core/ofnode.c | 13 +++++++------ include/dm/ofnode.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 6c771e364f..554af95114 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -299,11 +299,10 @@ ofnode ofnode_get_by_phandle(uint phandle) return node; }
-fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size) +fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *psize) { int na, ns; - - *size = FDT_SIZE_T_NONE; + fdt_size_t size = FDT_SIZE_T_NONE;
if (ofnode_is_np(node)) { const __be32 *prop_val; @@ -314,8 +313,7 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size) &flags); if (!prop_val) return FDT_ADDR_T_NONE; - if (size) - *size = size64; + size = size64;
ns = of_n_size_cells(ofnode_to_np(node));
@@ -330,9 +328,12 @@ fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size) ns = ofnode_read_simple_size_cells(ofnode_get_parent(node)); return fdtdec_get_addr_size_fixed(gd->fdt_blob, ofnode_to_offset(node), "reg", - index, na, ns, size, true); + index, na, ns, psize, true); }
+ if (size) + *psize = size; + return FDT_ADDR_T_NONE; }
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 8a69fd87da..e38d39dcf3 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -487,7 +487,7 @@ int ofnode_read_size(ofnode node, const char *propname); * @return address, or FDT_ADDR_T_NONE if not present or invalid */ phys_addr_t ofnode_get_addr_size_index(ofnode node, int index, - fdt_size_t *size); + fdt_size_t *psize);
/** * ofnode_get_addr_index() - get an address from a node -- 2.27.0

On Thu, 13 May 2021 at 01:38, chenguanqiao chenguanqiao@kuaishou.com wrote:
From: Chen Guanqiao chenguanqiao@kuaishou.com
Fixed a defect of a null pointer being discovered by Coverity Scan: CID 331544: Null pointer dereferences (REVERSE_INULL) Null-checking "size" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
Signed-off-by: Chen Guanqiao chenguanqiao@kuaishou.com
drivers/core/ofnode.c | 13 +++++++------ include/dm/ofnode.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Hi Chenguanqiao,
On Sat, 15 May 2021 at 09:20, Simon Glass sjg@chromium.org wrote:
On Thu, 13 May 2021 at 01:38, chenguanqiao chenguanqiao@kuaishou.com wrote:
From: Chen Guanqiao chenguanqiao@kuaishou.com
Fixed a defect of a null pointer being discovered by Coverity Scan: CID 331544: Null pointer dereferences (REVERSE_INULL) Null-checking "size" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
Signed-off-by: Chen Guanqiao chenguanqiao@kuaishou.com
drivers/core/ofnode.c | 13 +++++++------ include/dm/ofnode.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Unfortunately this does not apply to u-boot/next. Can you please rebase it and resend?
Regards, Simon
participants (2)
-
chenguanqiao
-
Simon Glass