All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/1] device property: Add fwnode_name_eq()
@ 2023-11-03  7:06 Sakari Ailus
  2023-11-06 11:29 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Sakari Ailus @ 2023-11-03  7:06 UTC (permalink / raw)
  To: linux-acpi, rafael
  Cc: Laurent Pinchart, Andy Shevchenko, linux-media, Paul Elder,
	Hans Verkuil, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Matthias Brugger, AngeloGioacchino Del Regno, Julien Stephan,
	devicetree, linux-mediatek

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.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
since v3:

- Use ptrdiff_t type for len.

 drivers/base/property.c  | 28 ++++++++++++++++++++++++++++
 include/linux/property.h |  1 +
 2 files changed, 29 insertions(+)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 8667b13639d2..f20379c9a5c9 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -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;
+	ptrdiff_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
diff --git a/include/linux/property.h b/include/linux/property.h
index 083a1f41364b..096ade186601 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 1/1] device property: Add fwnode_name_eq()
  2023-11-03  7:06 [PATCH v4 1/1] device property: Add fwnode_name_eq() Sakari Ailus
@ 2023-11-06 11:29 ` Andy Shevchenko
  2023-11-06 12:32   ` Sakari Ailus
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2023-11-06 11:29 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-acpi, rafael, Laurent Pinchart, linux-media, Paul Elder,
	Hans Verkuil, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Matthias Brugger, AngeloGioacchino Del Regno, Julien Stephan,
	devicetree, linux-mediatek

On Fri, Nov 03, 2023 at 09:06:31AM +0200, Sakari Ailus wrote:
> 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.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

I believe I gave already the tag...

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 1/1] device property: Add fwnode_name_eq()
  2023-11-06 11:29 ` Andy Shevchenko
@ 2023-11-06 12:32   ` Sakari Ailus
  0 siblings, 0 replies; 3+ messages in thread
From: Sakari Ailus @ 2023-11-06 12:32 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-acpi, rafael, Laurent Pinchart, linux-media, Paul Elder,
	Hans Verkuil, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Matthias Brugger, AngeloGioacchino Del Regno, Julien Stephan,
	devicetree, linux-mediatek

On Mon, Nov 06, 2023 at 01:29:22PM +0200, Andy Shevchenko wrote:
> On Fri, Nov 03, 2023 at 09:06:31AM +0200, Sakari Ailus wrote:
> > 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.
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> I believe I gave already the tag...

I guess I've missed it earlier... Thanks!

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-06 12:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-03  7:06 [PATCH v4 1/1] device property: Add fwnode_name_eq() Sakari Ailus
2023-11-06 11:29 ` Andy Shevchenko
2023-11-06 12:32   ` Sakari Ailus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.