summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2018-08-27 14:50:47 +0200
committerRob Herring <robh@kernel.org>2018-08-30 20:53:05 +0200
commitf42b0e18f2e5cf34f73ef1b6327b49040b307a33 (patch)
tree483166e1216f21bc0ebabe76553a2c7940b0e9ca /drivers
parentof: add helper to lookup compatible child node (diff)
downloadlinux-f42b0e18f2e5cf34f73ef1b6327b49040b307a33.tar.xz
linux-f42b0e18f2e5cf34f73ef1b6327b49040b307a33.zip
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/base.c22
1 files changed, 22 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);
*/
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;