[Skiboot] [PATCH 6/8] find_shared() - Check for return value from dt_find_property

Kamalesh Babulal kamalesh at linux.vnet.ibm.com
Tue Jun 23 18:37:36 AEST 2015


In find_shared(), dt_find_property might return NULL value,
so check for validity of the pointer before dereferencing it.

Fixes Coverity defect#97846.

Signed-off-by: Kamalesh Babulal <kamalesh at linux.vnet.ibm.com>
---
 hdata/memory.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hdata/memory.c b/hdata/memory.c
index 352dc71..6bc8695 100644
--- a/hdata/memory.c
+++ b/hdata/memory.c
@@ -69,7 +69,7 @@ static struct dt_node *find_shared(struct dt_node *root, u16 id, u64 start, u64
 
 	for (i = dt_first(root); i; i = dt_next(root, i)) {
 		__be64 reg[2];
-		const struct dt_property *shared, *type;
+		const struct dt_property *shared, *type, *region;
 
 		type = dt_find_property(i, "device_type");
 		if (!type || strcmp(type->prop, "memory") != 0)
@@ -79,7 +79,10 @@ static struct dt_node *find_shared(struct dt_node *root, u16 id, u64 start, u64
 		if (!shared || fdt32_to_cpu(*(u32 *)shared->prop) != id)
 			continue;
 
-		memcpy(reg, dt_find_property(i, "reg")->prop, sizeof(reg));
+		region = dt_find_property(i, "reg");
+		if (!region)
+			continue;
+		memcpy(reg, region->prop, sizeof(reg));
 		if (be64_to_cpu(reg[0]) == start && be64_to_cpu(reg[1]) == len)
 			break;
 	}
-- 
2.1.2



More information about the Skiboot mailing list