Skip to content

Commit 1666fae

Browse files
Heikki Krogerusrafaeljw
authored andcommitted
software node: Add software_node_find_by_name()
Function that searches software nodes by node name. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Tested-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent a55aa89 commit 1666fae

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎drivers/base/swnode.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,43 @@ static const struct fwnode_operations software_node_ops = {
620620

621621
/* -------------------------------------------------------------------------- */
622622

623+
/**
624+
* software_node_find_by_name - Find software node by name
625+
* @parent: Parent of the software node
626+
* @name: Name of the software node
627+
*
628+
* The function will find a node that is child of @parent and that is named
629+
* @name. If no node is found, the function returns NULL.
630+
*
631+
* NOTE: you will need to drop the reference with fwnode_handle_put() after use.
632+
*/
633+
const struct software_node *
634+
software_node_find_by_name(const struct software_node *parent, const char *name)
635+
{
636+
struct swnode *swnode;
637+
struct kobject *k;
638+
639+
if (!name)
640+
return NULL;
641+
642+
spin_lock(&swnode_kset->list_lock);
643+
644+
list_for_each_entry(k, &swnode_kset->list, entry) {
645+
swnode = kobj_to_swnode(k);
646+
if (parent == swnode->node->parent && swnode->node->name &&
647+
!strcmp(name, swnode->node->name)) {
648+
kobject_get(&swnode->kobj);
649+
break;
650+
}
651+
swnode = NULL;
652+
}
653+
654+
spin_unlock(&swnode_kset->list_lock);
655+
656+
return swnode ? swnode->node : NULL;
657+
}
658+
EXPORT_SYMBOL_GPL(software_node_find_by_name);
659+
623660
static int
624661
software_node_register_properties(struct software_node *node,
625662
const struct property_entry *properties)

‎include/linux/property.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ bool is_software_node(const struct fwnode_handle *fwnode);
421421
const struct software_node *to_software_node(struct fwnode_handle *fwnode);
422422
struct fwnode_handle *software_node_fwnode(const struct software_node *node);
423423

424+
const struct software_node *
425+
software_node_find_by_name(const struct software_node *parent,
426+
const char *name);
427+
424428
int software_node_register_nodes(const struct software_node *nodes);
425429
void software_node_unregister_nodes(const struct software_node *nodes);
426430

0 commit comments

Comments
 (0)