From 1d8f062ebc972053318c3a0e0470c7e0ddc1ebee Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Sat, 22 Dec 2018 12:49:39 +0000 Subject: [PATCH 1/2] drivers: base: swnode: check if pointer p is NULL before dereferencing it The pointer p can be potentially NULL as macro to_software_node can return NULL. Add null check on p before dereferencing it to avoid any NULL pointer dereferences. Detected by CoverityScan, CID#1476039 ("Explicit null dereferenced") Fixes: 59abd83672f7 (drivers: base: Introducing software nodes to the firmware node framework) Signed-off-by: Colin Ian King Signed-off-by: Rafael J. Wysocki --- drivers/base/swnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 306bb93287af..28b6eb0e5187 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -487,7 +487,7 @@ software_node_get_next_child(const struct fwnode_handle *fwnode, struct software_node *p = to_software_node(fwnode); struct software_node *c = to_software_node(child); - if (list_empty(&p->children) || + if (!p || list_empty(&p->children) || (c && list_is_last(&c->entry, &p->children))) return NULL; From f4747b9c68b8864cac32cddc45fdcfdfafb3397c Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Sat, 22 Dec 2018 12:43:33 +0000 Subject: [PATCH 2/2] drivers: base: swnode: check if swnode is NULL before dereferencing it The to_software_mode() macro can potentially return NULL, so also add a NULL check on swnode before dereferencing it to avoid any NULL pointer dereferences. Detected by CoverityScan, CID#1476052 ("Explicit null dereferenced") Fixes: 59abd83672f7 (drivers: base: Introducing software nodes to the firmware node framework) Signed-off-by: Colin Ian King Signed-off-by: Rafael J. Wysocki --- drivers/base/swnode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 28b6eb0e5187..89ad8dee6ad5 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -477,7 +477,8 @@ software_node_get_parent(const struct fwnode_handle *fwnode) { struct software_node *swnode = to_software_node(fwnode); - return swnode->parent ? &swnode->parent->fwnode : NULL; + return swnode ? (swnode->parent ? &swnode->parent->fwnode : NULL) : + NULL; } struct fwnode_handle *