Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit debd3a3b authored by Sakari Ailus's avatar Sakari Ailus Committed by Rob Herring
Browse files

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: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: default avatarKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent 1df09bc6
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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)
{