[4.4.y-cip,2/9] of: add node name compare helper functions
diff mbox series

Message ID 20200728104330.6182-3-biju.das.jz@bp.renesas.com
State Accepted
Delegated to: Nobuhiro Iwamatsu
Headers show
Series
  • Add LCD Panel support for RZ/G1E board
Related show

Commit Message

Biju Das July 28, 2020, 10:43 a.m. UTC
From: Rob Herring <robh@kernel.org>

commit f42b0e18f2e5cf34f73ef1b6327b49040b307a33 upstream.

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>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/of/base.c  | 22 ++++++++++++++++++++++
 include/linux/of.h | 13 +++++++++++++
 2 files changed, 35 insertions(+)

Patch
diff mbox series

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 164eb1306661..b02f4b272e5b 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)
 {
 	const __be32 *ip;
diff --git a/include/linux/of.h b/include/linux/of.h
index a09b9fb8e67d..1bef273a1909 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -231,6 +231,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>";
@@ -397,6 +400,16 @@  static inline struct device_node *to_of_node(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>";