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

chenguanqiao chenguanqiao at kuaishou.com
Thu May 13 09:38:45 CEST 2021


From: Chen Guanqiao <chenguanqiao at 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 at 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



More information about the U-Boot mailing list