Skip to content

Commit d20dc14

Browse files
Sakari Ailusrobherring
authored andcommitted
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>
1 parent debd3a3 commit d20dc14

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎include/linux/of.h‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
148148
#ifdef CONFIG_OF
149149
void of_core_init(void);
150150

151-
static inline bool is_of_node(struct fwnode_handle *fwnode)
151+
static inline bool is_of_node(const struct fwnode_handle *fwnode)
152152
{
153153
return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
154154
}
155155

156-
static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
157-
{
158-
return is_of_node(fwnode) ?
159-
container_of(fwnode, struct device_node, fwnode) : NULL;
160-
}
156+
#define to_of_node(__fwnode) \
157+
({ \
158+
typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
159+
\
160+
is_of_node(__to_of_node_fwnode) ? \
161+
container_of(__to_of_node_fwnode, \
162+
struct device_node, fwnode) : \
163+
NULL; \
164+
})
161165

162166
#define of_fwnode_handle(node) \
163167
({ \
@@ -539,12 +543,12 @@ static inline void of_core_init(void)
539543
{
540544
}
541545

542-
static inline bool is_of_node(struct fwnode_handle *fwnode)
546+
static inline bool is_of_node(const struct fwnode_handle *fwnode)
543547
{
544548
return false;
545549
}
546550

547-
static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
551+
static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
548552
{
549553
return NULL;
550554
}

0 commit comments

Comments
 (0)