Skip to content

Commit 1ced1ae

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
UPSTREAM: of: Make of_fwnode_handle() safer
On the expense of a little bit more complexity in the of_fwnode_handle() macro, make the macro result in NULL in case its argument is NULL while still referencing it only once. BUG=b:64133998 TEST=Run on DT system with GPIO LEDs Change-Id: I190e536298a7a04e4d4182722b27fd36725c4805 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> Signed-off-by: Guenter Roeck <groeck@chromium.org> (cherry picked from commit debd3a3b27c76c65a7d032b6f01710e6a6d555ab) Reviewed-on: https://chromium-review.googlesource.com/766070 Reviewed-by: Tomasz Figa <tfiga@chromium.org> Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
1 parent 68ef162 commit 1ced1ae

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

include/linux/of.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
144144
container_of(fwnode, struct device_node, fwnode) : NULL;
145145
}
146146

147-
#define of_fwnode_handle(node) (&(node)->fwnode)
147+
#define of_fwnode_handle(node) \
148+
({ \
149+
typeof(node) __of_fwnode_handle_node = (node); \
150+
\
151+
__of_fwnode_handle_node ? \
152+
&__of_fwnode_handle_node->fwnode : NULL; \
153+
})
148154

149155
static inline bool of_have_populated_dt(void)
150156
{

0 commit comments

Comments
 (0)