1 From d20dc1493db438fbbfb7733adc82f472dd8a0789 Mon Sep 17 00:00:00 2001
2 From: Sakari Ailus <sakari.ailus@linux.intel.com>
3 Date: Wed, 24 May 2017 17:53:55 +0300
4 Subject: of: Support const and non-const use for to_of_node()
6 From: Sakari Ailus <sakari.ailus@linux.intel.com>
8 commit d20dc1493db438fbbfb7733adc82f472dd8a0789 upstream.
10 Turn to_of_node() into a macro in order to support both const and
11 non-const use. Additionally make the fwnode argument to is_of_node() const
14 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
15 Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
16 Signed-off-by: Rob Herring <robh@kernel.org>
17 Cc: Nathan Chancellor <natechancellor@gmail.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 include/linux/of.h | 20 ++++++++++++--------
22 1 file changed, 12 insertions(+), 8 deletions(-)
24 --- a/include/linux/of.h
25 +++ b/include/linux/of.h
26 @@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
28 void of_core_init(void);
30 -static inline bool is_of_node(struct fwnode_handle *fwnode)
31 +static inline bool is_of_node(const struct fwnode_handle *fwnode)
33 return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
36 -static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
38 - return is_of_node(fwnode) ?
39 - container_of(fwnode, struct device_node, fwnode) : NULL;
41 +#define to_of_node(__fwnode) \
43 + typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
45 + is_of_node(__to_of_node_fwnode) ? \
46 + container_of(__to_of_node_fwnode, \
47 + struct device_node, fwnode) : \
51 static inline bool of_have_populated_dt(void)
53 @@ -529,12 +533,12 @@ static inline void of_core_init(void)
57 -static inline bool is_of_node(struct fwnode_handle *fwnode)
58 +static inline bool is_of_node(const struct fwnode_handle *fwnode)
63 -static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
64 +static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)