diff options
author | Rob Herring <robh@kernel.org> | 2018-08-27 08:50:47 -0400 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2018-08-30 14:53:05 -0400 |
commit | f42b0e18f2e5cf34f73ef1b6327b49040b307a33 (patch) | |
tree | 483166e1216f21bc0ebabe76553a2c7940b0e9ca | |
parent | 36156f9241cb0f9e37d998052873ca7501ad4b36 (diff) |
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 <frowand.list@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r-- | drivers/of/base.c | 22 | ||||
-rw-r--r-- | include/linux/of.h | 13 |
2 files changed, 35 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index bc420d2aa5f5..9095b8290150 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex); | |||
54 | */ | 54 | */ |
55 | DEFINE_RAW_SPINLOCK(devtree_lock); | 55 | DEFINE_RAW_SPINLOCK(devtree_lock); |
56 | 56 | ||
57 | bool of_node_name_eq(const struct device_node *np, const char *name) | ||
58 | { | ||
59 | const char *node_name; | ||
60 | size_t len; | ||
61 | |||
62 | if (!np) | ||
63 | return false; | ||
64 | |||
65 | node_name = kbasename(np->full_name); | ||
66 | len = strchrnul(node_name, '@') - node_name; | ||
67 | |||
68 | return (strlen(name) == len) && (strncmp(node_name, name, len) == 0); | ||
69 | } | ||
70 | |||
71 | bool of_node_name_prefix(const struct device_node *np, const char *prefix) | ||
72 | { | ||
73 | if (!np) | ||
74 | return false; | ||
75 | |||
76 | return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0; | ||
77 | } | ||
78 | |||
57 | int of_n_addr_cells(struct device_node *np) | 79 | int of_n_addr_cells(struct device_node *np) |
58 | { | 80 | { |
59 | u32 cells; | 81 | u32 cells; |
diff --git a/include/linux/of.h b/include/linux/of.h index b99a1a8c2952..688c52dd7b3e 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) | |||
256 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) | 256 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) |
257 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) | 257 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) |
258 | 258 | ||
259 | extern bool of_node_name_eq(const struct device_node *np, const char *name); | ||
260 | extern bool of_node_name_prefix(const struct device_node *np, const char *prefix); | ||
261 | |||
259 | static inline const char *of_node_full_name(const struct device_node *np) | 262 | static inline const char *of_node_full_name(const struct device_node *np) |
260 | { | 263 | { |
261 | return np ? np->full_name : "<no-node>"; | 264 | return np ? np->full_name : "<no-node>"; |
@@ -563,6 +566,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode) | |||
563 | return NULL; | 566 | return NULL; |
564 | } | 567 | } |
565 | 568 | ||
569 | static inline bool of_node_name_eq(const struct device_node *np, const char *name) | ||
570 | { | ||
571 | return false; | ||
572 | } | ||
573 | |||
574 | static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix) | ||
575 | { | ||
576 | return false; | ||
577 | } | ||
578 | |||
566 | static inline const char* of_node_full_name(const struct device_node *np) | 579 | static inline const char* of_node_full_name(const struct device_node *np) |
567 | { | 580 | { |
568 | return "<no-node>"; | 581 | return "<no-node>"; |