Skip to content

Commit

Permalink
drivers: base: swnode: check if swnode is NULL before dereferencing it
Browse files Browse the repository at this point in the history
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: 59abd83 (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>
  • Loading branch information
Colin Ian King authored and Rafael J. Wysocki committed Dec 26, 2018
1 parent 1d8f062 commit f4747b9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/base/swnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit f4747b9

Please sign in to comment.