Skip to content

Commit

Permalink
of: Make of_fwnode_handle() safer
Browse files Browse the repository at this point in the history
On the expense of a little bit more complexity in the of_fwnode_handle()
macro, make the macro result in NULL in case its argument is NULL while
still referencing it only once.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
Sakari Ailus authored and Rob Herring committed Jun 1, 2017
1 parent 1df09bc commit debd3a3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
container_of(fwnode, struct device_node, fwnode) : NULL;
}

#define of_fwnode_handle(node) (&(node)->fwnode)
#define of_fwnode_handle(node) \
({ \
typeof(node) __of_fwnode_handle_node = (node); \
\
__of_fwnode_handle_node ? \
&__of_fwnode_handle_node->fwnode : NULL; \
})

static inline bool of_have_populated_dt(void)
{
Expand Down

0 comments on commit debd3a3

Please sign in to comment.