Blob Blame History Raw
From: Sakari Ailus <sakari.ailus@linux.intel.com>
Date: Wed, 24 May 2017 17:53:54 +0300
Subject: of: Make of_fwnode_handle() safer
Patch-mainline: v4.13-rc1
Git-commit: debd3a3b27c76c65a7d032b6f01710e6a6d555ab
References: bsc#1098633

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>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 include/linux/of.h |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -159,7 +159,13 @@ static inline struct device_node *to_of_
 		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)
 {