diff options
author | Heikki Krogerus <heikki.krogerus@linux.intel.com> | 2019-08-19 13:07:22 +0300 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2019-08-26 11:35:13 +0200 |
commit | 1666faedb567d03cde1d656ae24c6cc253e67373 (patch) | |
tree | e83b326e0893b037bbd41e7f80e95b13c428892f /drivers/base/swnode.c | |
parent | a55aa89aab90fae7c815b0551b07be37db359d76 (diff) |
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>
Diffstat (limited to 'drivers/base/swnode.c')
-rw-r--r-- | drivers/base/swnode.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index e7b3aa3bd55a..ee2a405cca9a 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -620,6 +620,43 @@ static const struct fwnode_operations software_node_ops = { /* -------------------------------------------------------------------------- */ +/** + * software_node_find_by_name - Find software node by name + * @parent: Parent of the software node + * @name: Name of the software node + * + * The function will find a node that is child of @parent and that is named + * @name. If no node is found, the function returns NULL. + * + * NOTE: you will need to drop the reference with fwnode_handle_put() after use. + */ +const struct software_node * +software_node_find_by_name(const struct software_node *parent, const char *name) +{ + struct swnode *swnode; + struct kobject *k; + + if (!name) + return NULL; + + spin_lock(&swnode_kset->list_lock); + + list_for_each_entry(k, &swnode_kset->list, entry) { + swnode = kobj_to_swnode(k); + if (parent == swnode->node->parent && swnode->node->name && + !strcmp(name, swnode->node->name)) { + kobject_get(&swnode->kobj); + break; + } + swnode = NULL; + } + + spin_unlock(&swnode_kset->list_lock); + + return swnode ? swnode->node : NULL; +} +EXPORT_SYMBOL_GPL(software_node_find_by_name); + static int software_node_register_properties(struct software_node *node, const struct property_entry *properties) |