From: Kishon Vijay Abraham I <kishon@ti.com>
Date: Wed, 21 Jul 2021 15:58:30 +0000 (+0530)
Subject: dm: core: Add helper to compare node names
X-Git-Tag: v2025.01-rc5-pxa1908~1772^2~33
X-Git-Url: http://git.dujemihanovic.xyz/%22http:/kyber.dk/phpMyBuilder/static/%7B%7B?a=commitdiff_plain;h=77cbaf8837fd096b876d8a6c05d90683f5f4b82e;p=u-boot.git

dm: core: Add helper to compare node names

Add helper to compare node names.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20210721155849.20994-2-kishon@ti.com
---

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index dda6c76e83..701b23e2c9 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -18,6 +18,19 @@
 #include <linux/ioport.h>
 #include <asm/global_data.h>
 
+bool ofnode_name_eq(ofnode node, const char *name)
+{
+	const char *node_name;
+	size_t len;
+
+	assert(ofnode_valid(node));
+
+	node_name = ofnode_get_name(node);
+	len = strchrnul(node_name, '@') - node_name;
+
+	return (strlen(name) == len) && !strncmp(node_name, name, len);
+}
+
 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
 {
 	return ofnode_read_u32_index(node, propname, 0, outp);
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 3da05d8b21..4e1a8447e6 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -231,6 +231,16 @@ static inline ofnode ofnode_root(void)
 	return node;
 }
 
+/**
+ * ofnode_name_eq() - Check if the node name is equivalent to a given name
+ *                    ignoring the unit address
+ *
+ * @node:	valid node reference that has to be compared
+ * @name:	name that has to be compared with the node name
+ * @return true if matches, false if it doesn't match
+ */
+bool ofnode_name_eq(ofnode node, const char *name);
+
 /**
  * ofnode_read_u32() - Read a 32-bit integer from a property
  *