drivers: base: swnode: check if pointer p is NULL before dereferencing it
authorColin Ian King <colin.king@canonical.com>
Sat, 22 Dec 2018 12:49:39 +0000 (12:49 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 26 Dec 2018 09:48:01 +0000 (10:48 +0100)
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 <colin.king@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/swnode.c

index 306bb93287af32effbb0953a91ed6ccbea5d6410..28b6eb0e518708913d2198e47b61178646a1c8a6 100644 (file)
@@ -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;