Skip to contentSkip to conversation

device property: Add fwnode_name_eq()

PATCH Superseded Sakari Ailus 2 participants 3 messages Nov 2, 2023 – Nov 6, 2023

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sakari Ailus

author reviewer
#0 lore raw

PATCH v3 1/1 device property: Add fwnode_name_eq()

Add fwnode_name_eq() to implement the functionality of of_node_name_eq() on fwnode property API. The same convention of ending the comparison at '@' (besides NUL) is applied on also both ACPI and swnode. The function is intended for comparing unit address-less node names on DT and firmware or swnodes compliant with DT bindings.

---
Hi Rafael,

Could we merge this via the media tree (pending further review comments,
if any)? There'a a patch to be merged via that tree which will depend on
fwnode_name_eq(), namely:
<URL:https://lore.kernel.org/linux-media/[email protected]/T/#m489b7e83cbc755815c5002f85454a76bfb41adb2>.

since v2:

- Use NUL instead of '\0' and "at" instead of "to" (before "stopping comparison").

 drivers/base/property.c  | 28 ++++++++++++++++++++++++++++
 include/linux/property.h |  1 +
 2 files changed, 29 insertions(+)
drivers/base/property.c +28 -0
index 8667b13639d2..572e065e8797 100644
@@ -595,6 +595,34 @@ const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
 	return fwnode_call_ptr_op(fwnode, get_name_prefix);
 }
 
+/**
+ * fwnode_name_eq - Return true if node name is equal
+ * @fwnode: The firmware node
+ * @name: The name to which to compare the node name
+ *
+ * Compare the name provided as an argument to the name of the node, stopping
+ * the comparison at either NUL or '@' character, whichever comes first. This
+ * function is generally used for comparing node names while ignoring the
+ * possible unit address of the node.
+ *
+ * Return: true if the node name matches with the name provided in the @name
+ * argument, false otherwise.
+ */
+bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name)
+{
+	const char *node_name;
+	size_t len;
+
+	node_name = fwnode_get_name(fwnode);
+	if (!node_name)
+		return false;
+
+	len = strchrnul(node_name, '@') - node_name;
+
+	return str_has_prefix(node_name, name) == len;
+}
+EXPORT_SYMBOL_GPL(fwnode_name_eq);
+
 /**
  * fwnode_get_parent - Return parent firwmare node
  * @fwnode: Firmware whose parent is retrieved
include/linux/property.h +1 -0
index 083a1f41364b..096ade186601 100644
@@ -108,6 +108,7 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
 
 const char *fwnode_get_name(const struct fwnode_handle *fwnode);
 const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
+bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name);
 
 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
Signature · 1 line
2.39.2
maintainer Acked-by on v3 1/1
#1 lore raw
Quoted 7 lines · Sakari Ailus

Add fwnode_name_eq() to implement the functionality of of_node_name_eq() on fwnode property API. The same convention of ending the comparison at '@' (besides NUL) is applied on also both ACPI and swnode. The function is intended for comparing unit address-less node names on DT and firmware or swnodes compliant with DT bindings.

Quoted 8 lines

---
Hi Rafael,

Could we merge this via the media tree (pending further review comments, if any)?

This would be fine with me, so please feel free to add

to this patch (when ready), but you need to ask Greg about it, because he's been handling device properties changes lately.

Quoted 67 lines

There'a a patch to be merged via that tree which will depend on
fwnode_name_eq(), namely:
<URL:https://lore.kernel.org/linux-media/[email protected]/T/#m489b7e83cbc755815c5002f85454a76bfb41adb2>.

since v2:

- Use NUL instead of '\0' and "at" instead of "to" (before "stopping comparison").

 drivers/base/property.c  | 28 ++++++++++++++++++++++++++++
 include/linux/property.h |  1 +
 2 files changed, 29 insertions(+)
drivers/base/property.c +28 -0
index 8667b13639d2..572e065e8797 100644
@@ -595,6 +595,34 @@ const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode)
        return fwnode_call_ptr_op(fwnode, get_name_prefix);
 }
 
+/**
+ * fwnode_name_eq - Return true if node name is equal
+ * @fwnode: The firmware node
+ * @name: The name to which to compare the node name
+ *
+ * Compare the name provided as an argument to the name of the node, stopping
+ * the comparison at either NUL or '@' character, whichever comes first. This
+ * function is generally used for comparing node names while ignoring the
+ * possible unit address of the node.
+ *
+ * Return: true if the node name matches with the name provided in the @name
+ * argument, false otherwise.
+ */
+bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name)
+{
+       const char *node_name;
+       size_t len;
+
+       node_name = fwnode_get_name(fwnode);
+       if (!node_name)
+               return false;
+
+       len = strchrnul(node_name, '@') - node_name;
+
+       return str_has_prefix(node_name, name) == len;
+}
+EXPORT_SYMBOL_GPL(fwnode_name_eq);
+
 /**
  * fwnode_get_parent - Return parent firwmare node
  * @fwnode: Firmware whose parent is retrieved
include/linux/property.h +1 -1
index 083a1f41364b..096ade186601 100644
@@ -108,6 +108,7 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
 
 const char *fwnode_get_name(const struct fwnode_handle *fwnode);
 const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
+bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name);
 
 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
 struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);
--

2.39.2

author reviewer
#2 lore raw

Hi Rafael,

Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Sakari Ailus

Add fwnode_name_eq() to implement the functionality of of_node_name_eq() on fwnode property API. The same convention of ending the comparison at '@' (besides NUL) is applied on also both ACPI and swnode. The function is intended for comparing unit address-less node names on DT and firmware or swnodes compliant with DT bindings.

---
Hi Rafael,

Quoted 6 lines
Quoted 2 lines

Could we merge this via the media tree (pending further review comments, if any)?

This would be fine with me, so please feel free to add

Thanks!

Quoted 3 lines

to this patch (when ready), but you need to ask Greg about it, because he's been handling device properties changes lately.

I must have missed this somehow... I'll resend v4.

Signature · 3 lines
Regards,

Sakari Ailus