Skip to contentSkip to conversation

device property: Avoid NULL pointer dereference in device_get_next_child_node()

PATCH In review Andy Shevchenko 2 participants 2 messages Jul 16, 2020 – Jul 17, 2020

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 device property: Avoid NULL pointer dereference in device_get_next_child_node()

When we have no primary fwnode or when it's a software node, we may end up in the situation when fwnode is a NULL pointer. There is no point to look for secondary fwnode in such case. Add a necessary check to a condition.

Fixes 114dbb4fa7c4 ("drivers property: When no children in primary, try secondary")
---
 drivers/base/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/property.c +1 -1
index 1e6d75e65938..d58aa98fe964 100644
@@ -721,7 +721,7 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
 		return next;
 
 	/* When no more children in primary, continue with secondary */
-	if (!IS_ERR_OR_NULL(fwnode->secondary))
+	if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary))
 		next = fwnode_get_next_child_node(fwnode->secondary, child);
 
 	return next;
Signature · 1 line
2.27.0
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andy Shevchenko

When we have no primary fwnode or when it's a software node, we may end up in the situation when fwnode is a NULL pointer. There is no point to look for secondary fwnode in such case. Add a necessary check to a condition.

Fixes 114dbb4fa7c4 ("drivers property: When no children in primary, try secondary")

Best regards,
Maxim Levitsky

Quoted 17 lines
---
 drivers/base/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/property.c +1 -1
index 1e6d75e65938..d58aa98fe964 100644
@@ -721,7 +721,7 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
 		return next;
 
 	/* When no more children in primary, continue with secondary */
-	if (!IS_ERR_OR_NULL(fwnode->secondary))
+	if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary))
 		next = fwnode_get_next_child_node(fwnode->secondary, child);
 
 	return next;