Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Sakari Ailus and committed by
Hans Verkuil
a9c8c738 03cc7fef

+29
+28
drivers/base/property.c
··· 595 595 } 596 596 597 597 /** 598 + * fwnode_name_eq - Return true if node name is equal 599 + * @fwnode: The firmware node 600 + * @name: The name to which to compare the node name 601 + * 602 + * Compare the name provided as an argument to the name of the node, stopping 603 + * the comparison at either NUL or '@' character, whichever comes first. This 604 + * function is generally used for comparing node names while ignoring the 605 + * possible unit address of the node. 606 + * 607 + * Return: true if the node name matches with the name provided in the @name 608 + * argument, false otherwise. 609 + */ 610 + bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name) 611 + { 612 + const char *node_name; 613 + ptrdiff_t len; 614 + 615 + node_name = fwnode_get_name(fwnode); 616 + if (!node_name) 617 + return false; 618 + 619 + len = strchrnul(node_name, '@') - node_name; 620 + 621 + return str_has_prefix(node_name, name) == len; 622 + } 623 + EXPORT_SYMBOL_GPL(fwnode_name_eq); 624 + 625 + /** 598 626 * fwnode_get_parent - Return parent firwmare node 599 627 * @fwnode: Firmware whose parent is retrieved 600 628 *
+1
include/linux/property.h
··· 109 109 110 110 const char *fwnode_get_name(const struct fwnode_handle *fwnode); 111 111 const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); 112 + bool fwnode_name_eq(const struct fwnode_handle *fwnode, const char *name); 112 113 113 114 struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); 114 115 struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);