aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2017-05-24 10:53:54 -0400
committerRob Herring <robh@kernel.org>2017-06-01 09:50:47 -0400
commitdebd3a3b27c76c65a7d032b6f01710e6a6d555ab (patch)
treebd872b01ad8b51c6a69eaf18e2bac10375c9c20c
parent1df09bc66f9bc146732628f8426787f35ab1804b (diff)
of: Make of_fwnode_handle() safer
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>
-rw-r--r--include/linux/of.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/include/linux/of.h b/include/linux/of.h
index 50fcdb54087f..f05c87f0c495 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -159,7 +159,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
159 container_of(fwnode, struct device_node, fwnode) : NULL; 159 container_of(fwnode, struct device_node, fwnode) : NULL;
160} 160}
161 161
162#define of_fwnode_handle(node) (&(node)->fwnode) 162#define of_fwnode_handle(node) \
163 ({ \
164 typeof(node) __of_fwnode_handle_node = (node); \
165 \
166 __of_fwnode_handle_node ? \
167 &__of_fwnode_handle_node->fwnode : NULL; \
168 })
163 169
164static inline bool of_have_populated_dt(void) 170static inline bool of_have_populated_dt(void)
165{ 171{