From debd3a3b27c76c65a7d032b6f01710e6a6d555ab Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Wed, 24 May 2017 17:53:54 +0300 Subject: 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. Signed-off-by: Sakari Ailus Reviewed-by: Kieran Bingham Signed-off-by: Rob Herring --- include/linux/of.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 50fcdb54087f..f05c87f0c495 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -159,7 +159,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) container_of(fwnode, struct device_node, fwnode) : NULL; } -#define of_fwnode_handle(node) (&(node)->fwnode) +#define of_fwnode_handle(node) \ + ({ \ + typeof(node) __of_fwnode_handle_node = (node); \ + \ + __of_fwnode_handle_node ? \ + &__of_fwnode_handle_node->fwnode : NULL; \ + }) static inline bool of_have_populated_dt(void) { -- cgit From d20dc1493db438fbbfb7733adc82f472dd8a0789 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Wed, 24 May 2017 17:53:55 +0300 Subject: 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 Reviewed-by: Kieran Bingham Signed-off-by: Rob Herring --- include/linux/of.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index f05c87f0c495..29b7b738b509 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -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) \ ({ \ @@ -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; } -- cgit From 3bc1630774bc9f202308ae04608a32c366b41caf Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 25 Apr 2017 19:38:48 +0200 Subject: of: Provide dummy of_device_compatible_match() for compile-testing Most of_device_*() functions have dummy versions for CONFIG_OF=n, but of_device_compatible_match() hasn't. Fix that to improve the ability to do compile-testing. Fixes: b9c13fe32faaa71c ("dt: Add of_device_compatible_match()") Signed-off-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- include/linux/of.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 50fcdb54087f..c72ba9437a43 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -627,6 +627,12 @@ static inline int of_device_is_compatible(const struct device_node *device, return 0; } +static inline int of_device_compatible_match(struct device_node *device, + const char *const *compat) +{ + return 0; +} + static inline bool of_device_is_available(const struct device_node *device) { return false; -- cgit From 92af08990cc49408119ca2549dfe9e37235864d8 Mon Sep 17 00:00:00 2001 From: Frank Rowand Date: Tue, 20 Jun 2017 16:38:28 -0700 Subject: of: make of_fdt_is_compatible() static The callers of of_fdt_is_compatible() are all in fdt.c so make it static. Signed-off-by: Frank Rowand Signed-off-by: Rob Herring --- include/linux/of_fdt.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include') diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index 1dfbfd0d8040..013c5418aeec 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -31,9 +31,6 @@ extern void *of_fdt_get_property(const void *blob, unsigned long node, const char *name, int *size); -extern int of_fdt_is_compatible(const void *blob, - unsigned long node, - const char *compat); extern bool of_fdt_is_big_endian(const void *blob, unsigned long node); extern int of_fdt_match(const void *blob, unsigned long node, -- cgit