Skip to content

Commit

Permalink
of: Support const and non-const use for to_of_node()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sakari Ailus authored and Rob Herring committed Jun 1, 2017
1 parent debd3a3 commit d20dc14
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
#ifdef CONFIG_OF
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;
}

static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
{
return is_of_node(fwnode) ?
container_of(fwnode, struct device_node, fwnode) : NULL;
}
#define to_of_node(__fwnode) \
({ \
typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
\
is_of_node(__to_of_node_fwnode) ? \
container_of(__to_of_node_fwnode, \
struct device_node, fwnode) : \
NULL; \
})

#define of_fwnode_handle(node) \
({ \
Expand Down Expand Up @@ -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;
}

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;
}
Expand Down

0 comments on commit d20dc14

Please sign in to comment.