]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.164/of-support-const-and-non-const-use-for-to_of_node.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.164 / of-support-const-and-non-const-use-for-to_of_node.patch
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()
5
6 From: Sakari Ailus <sakari.ailus@linux.intel.com>
7
8 commit d20dc1493db438fbbfb7733adc82f472dd8a0789 upstream.
9
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
12 as well.
13
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>
19
20 ---
21 include/linux/of.h | 20 ++++++++++++--------
22 1 file changed, 12 insertions(+), 8 deletions(-)
23
24 --- a/include/linux/of.h
25 +++ b/include/linux/of.h
26 @@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
27 #ifdef CONFIG_OF
28 void of_core_init(void);
29
30 -static inline bool is_of_node(struct fwnode_handle *fwnode)
31 +static inline bool is_of_node(const struct fwnode_handle *fwnode)
32 {
33 return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
34 }
35
36 -static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
37 -{
38 - return is_of_node(fwnode) ?
39 - container_of(fwnode, struct device_node, fwnode) : NULL;
40 -}
41 +#define to_of_node(__fwnode) \
42 + ({ \
43 + typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
44 + \
45 + is_of_node(__to_of_node_fwnode) ? \
46 + container_of(__to_of_node_fwnode, \
47 + struct device_node, fwnode) : \
48 + NULL; \
49 + })
50
51 static inline bool of_have_populated_dt(void)
52 {
53 @@ -529,12 +533,12 @@ static inline void of_core_init(void)
54 {
55 }
56
57 -static inline bool is_of_node(struct fwnode_handle *fwnode)
58 +static inline bool is_of_node(const struct fwnode_handle *fwnode)
59 {
60 return false;
61 }
62
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)
65 {
66 return NULL;
67 }