Skip to content

Commit f42b0e1

Browse files
committed
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>
1 parent 36156f9 commit f42b0e1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

drivers/of/base.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex);
5454
*/
5555
DEFINE_RAW_SPINLOCK(devtree_lock);
5656

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+
5779
int of_n_addr_cells(struct device_node *np)
5880
{
5981
u32 cells;

include/linux/of.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
256256
#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
257257
#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
258258

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+
259262
static inline const char *of_node_full_name(const struct device_node *np)
260263
{
261264
return np ? np->full_name : "<no-node>";
@@ -563,6 +566,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
563566
return NULL;
564567
}
565568

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+
566579
static inline const char* of_node_full_name(const struct device_node *np)
567580
{
568581
return "<no-node>";

0 commit comments

Comments
 (0)