of: add node name compare helper functions
Rob Herring
maintainerPATCH 1/1 of: add node name compare helper functions
In preparation to remove device_node.name pointer, add helper functions for node name comparisons which are a common pattern throughout the kernel.
Cc Frank Rowand <[email protected]>
Signed-off-by Rob Herring <[email protected]>
--- drivers/of/base.c | 22 ++++++++++++++++++++++ include/linux/of.h | 13 +++++++++++++ 2 files changed, 35 insertions(+)
drivers/of/base.c +22 -0
@@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex);*/ DEFINE_RAW_SPINLOCK (devtree_lock); +bool of_node_name_eq (const struct device_node *np,const char *name) +{ +const char *node_name; +size_t len; + +if (!np) +return false; + + node_name =kbasename (np->full_name); + len =strchrnul (node_name,'@' ) - node_name; + +return (strlen (name) == len) && (strncmp (node_name, name, len) ==0 ); +} + +bool of_node_name_prefix (const struct device_node *np,const char *prefix) +{ +if (!np) +return false; + +return strncmp (kbasename (np->full_name), prefix,strlen (prefix)) ==0 ; +} +int of_n_addr_cells (struct device_node *np) {u32 cells;
include/linux/of.h +13 -0
@@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)#define OF_IS_DYNAMIC (x) test_bit(OF_DYNAMIC, &x->_flags)#define OF_MARK_DYNAMIC (x) set_bit(OF_DYNAMIC, &x->_flags) +extern bool of_node_name_eq (const struct device_node *np,const char *name); +extern bool of_node_name_prefix (const struct device_node *np,const char *prefix); +static inline const char *of_node_full_name (const struct device_node *np) {return np ? np->full_name :"<no-node>" ;
@@ -561,6 +564,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)return NULL ; } +static inline bool of_node_name_eq (const struct device_node *np,const char *name) +{ +return false; +} + +static inline bool of_node_name_prefix (const struct device_node *np,const char *prefix) +{ +return false; +} +static inline const char *of_node_full_name (const struct device_node *np) {return "<no-node>" ;
Signature · 1 line
2.17.1
Quoted 23 lines · Rob Herring
In preparation to remove device_node.name pointer, add helper functions for node name comparisons which are a common pattern throughout the kernel.
Cc Frank Rowand <[email protected]>Signed-off-by Rob Herring <[email protected]>--- drivers/of/base.c | 22 ++++++++++++++++++++++ include/linux/of.h | 13 +++++++++++++ 2 files changed, 35 insertions(+)drivers/of/base.c +5
-0@@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex);*/ DEFINE_RAW_SPINLOCK (devtree_lock); +bool of_node_name_eq (const struct device_node *np,const char *name) +{ +const char *node_name; +size_t len; +
drivers/of/base.c DEFINE_MUTEX(of_mutex); · line 71
Quoted 10 lines
drivers/of/base.c +10
-0+if (!np) +return false; + + node_name =kbasename (np->full_name); + len =strchrnul (node_name,'@' ) - node_name; + +return (strlen (name) == len) && (strncmp (node_name, name, len) ==0 ); +} + +bool of_node_name_prefix (const struct device_node *np,const char *prefix)
of_node_name_prefix_eq() would be more clear and consistent.
of_node_name_prefix() sounds like it would return the prefix of *np.
Quoted 42 lines
drivers/of/base.c +7
-0+{ +if (!np) +return false; + +return strncmp (kbasename (np->full_name), prefix,strlen (prefix)) ==0 ; +} +int of_n_addr_cells (struct device_node *np) {u32 cells;include/linux/of.h +13
-0@@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)#define OF_IS_DYNAMIC (x) test_bit(OF_DYNAMIC, &x->_flags)#define OF_MARK_DYNAMIC (x) set_bit(OF_DYNAMIC, &x->_flags) +extern bool of_node_name_eq (const struct device_node *np,const char *name); +extern bool of_node_name_prefix (const struct device_node *np,const char *prefix); +static inline const char *of_node_full_name (const struct device_node *np) {return np ? np->full_name :"<no-node>" ;@@ -561,6 +564,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)return NULL ; } +static inline bool of_node_name_eq (const struct device_node *np,const char *name) +{ +return false; +} + +static inline bool of_node_name_prefix (const struct device_node *np,const char *prefix) +{ +return false; +} +static inline const char *of_node_full_name (const struct device_node *np) {return "<no-node>" ;