of: Support const and non-const use for to_of_node()

Turn to_of_node() into a macro in order to support both const and
non-const use. Additionally make the fwnode argument to is_of_node() const
as well.

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>
This commit is contained in:
Sakari Ailus
2017-05-24 17:53:55 +03:00
committed by Rob Herring
parent debd3a3b27
commit d20dc1493d

View File

@@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
#ifdef CONFIG_OF #ifdef CONFIG_OF
void of_core_init(void); void of_core_init(void);
static inline bool is_of_node(struct fwnode_handle *fwnode) static inline bool is_of_node(const struct fwnode_handle *fwnode)
{ {
return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF; return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
} }
static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) #define to_of_node(__fwnode) \
{ ({ \
return is_of_node(fwnode) ? typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
container_of(fwnode, struct device_node, fwnode) : NULL; \
} is_of_node(__to_of_node_fwnode) ? \
container_of(__to_of_node_fwnode, \
struct device_node, fwnode) : \
NULL; \
})
#define of_fwnode_handle(node) \ #define of_fwnode_handle(node) \
({ \ ({ \
@@ -539,12 +543,12 @@ static inline void of_core_init(void)
{ {
} }
static inline bool is_of_node(struct fwnode_handle *fwnode) static inline bool is_of_node(const struct fwnode_handle *fwnode)
{ {
return false; return false;
} }
static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
{ {
return NULL; return NULL;
} }