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: 114dbb4fa7 ("drivers property: When no children in primary, try secondary")
Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20200716182747.54929-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Andy Shevchenko 2020-07-16 21:27:47 +03:00 committed by Greg Kroah-Hartman
parent ba47d845d7
commit 29c4a54bc6

View file

@ -721,7 +721,7 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
return next; return next;
/* When no more children in primary, continue with secondary */ /* 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); next = fwnode_get_next_child_node(fwnode->secondary, child);
return next; return next;