device property: Add fwnode_name_eq()
Subsystems (5)
Sakari Ailus
reviewerPATCH v2 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 '\0') 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.
---
since v1:
- Use str_has_prefix().
- Fix kernel-doc for @fwnode argument.
- Use size_t type for len.
The patch is untested.
drivers/base/property.c | 28 ++++++++++++++++++++++++++++ include/linux/property.h | 1 + 2 files changed, 29 insertions(+)
drivers/base/property.c +28 -0
@@ -594,6 +594,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 to either '\0' 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
@@ -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
Andy Shevchenko
reviewerQuoted 5 lines · Sakari Ailus
Add
fwnode_name_eq()to implement the functionality ofof_node_name_eq()on fwnode property API. The same convention of ending the comparison at '@' (besides '\0') 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 1 line
- Use
size_ttype for len.
Strictly speaking it should be ptrdiff_t according to the code.
...
Quoted 1 line
+ * the comparison to either '\0' or '@' character
NUL is a human-readable substitution to less parsable '\0'.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerQuoted 7 lines · Andy Shevchenko
Quoted 5 lines · Sakari Ailus
Add
fwnode_name_eq()to implement the functionality ofof_node_name_eq()on fwnode property API. The same convention of ending the comparison at '@' (besides '\0') 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 5 lines
...
Quoted 1 line
- Use
size_ttype for len.Strictly speaking it should be
ptrdiff_taccording to the code.
It'll be compared to size_t right after. ptrdiff_t is signed and we know we have a positive number here so size_t seems like a better choice.
Quoted 6 lines
...
Quoted 1 line
+ * the comparison to either '\0' or '@' character
NUL is a human-readable substitution to less parsable '\0'.
I can send v3 with that but I'll wait a bit if there are more comments.
Signature · 1 line
Sakari Ailus
Andy Shevchenko
reviewerQuoted 2 lines · Sakari Ailus
Quoted 1 line · Andy Shevchenko
On Wed, Nov 01, 2023 at 09:27:29AM +0200, Sakari Ailus wrote:
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
- Use
size_ttype for len.Strictly speaking it should be
ptrdiff_taccording to the code.It'll be compared to
size_tright after.ptrdiff_tis signed and we know we have a positive number here sosize_tseems like a better choice.
Yeah, this is downsides of C language and typing system. But diff between pointers returns ptrdiff_t result.
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+ * the comparison to either '\0' or '@' character
NUL is a human-readable substitution to less parsable '\0'.
I can send v3 with that but I'll wait a bit if there are more comments.
Why not? You got tags, so I'll give mine with this being addressed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
Add
fwnode_name_eq()to implement the functionality ofof_node_name_eq()on fwnode property API. The same convention of ending the comparison at '@' (besides '\0') 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 <[email protected]>
Quoted 10 lines
---
since v1:- Use
str_has_prefix().- Fix kernel-doc for @fwnode argument.
- Use
size_ttype for len.The patch is untested.
Not anymore :-)
Which tree will this get merged through ? The thp7312 driver depends on this patch, and I would like to get it in v6.8. If we can merge this through the media tree it could be the simplest option, otherwise I'll need a stable branch based on v6.7-rc1.
Quoted 55 lines
drivers/base/property.c | 28 ++++++++++++++++++++++++++++ include/linux/property.h | 1 + 2 files changed, 29 insertions(+)drivers/base/property.c +28
-0@@ -594,6 +594,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 to either '\0' 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@@ -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 · 3 lines
Regards, Laurent Pinchart