Re: [PATCH 1/3] software node: Add software_node_find_by_name()
On Thu, Aug 15, 2019 at 03:55:40PM +0300, Andy Shevchenko wrote: > On Thu, Aug 15, 2019 at 2:32 PM Heikki Krogerus > wrote: > > > > Function that searches software nodes by node name. > > > +/** > > + * 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. > > Shouldn't we add that the caller responsible of putting kobject? OK. I'll fix this and the other one too. Thanks Andy! -- heikki
Re: [PATCH 1/3] software node: Add software_node_find_by_name()
On Thu, Aug 15, 2019 at 2:32 PM Heikki Krogerus wrote: > > Function that searches software nodes by node name. > +/** > + * 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. Shouldn't we add that the caller responsible of putting kobject? > + */ > +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(_kset->list_lock); > + > + list_for_each_entry(k, _kset->list, entry) { > + swnode = kobj_to_swnode(k); > + if (parent == swnode->node->parent && swnode->node->name && > + !strcmp(name, swnode->node->name)) { > + kobject_get(>kobj); > + break; > + } > + swnode = NULL; > + } > + > + spin_unlock(_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) > diff --git a/include/linux/property.h b/include/linux/property.h > index 5a910ad79591..9b3d4ca3a73a 100644 > --- a/include/linux/property.h > +++ b/include/linux/property.h > @@ -421,6 +421,10 @@ bool is_software_node(const struct fwnode_handle > *fwnode); > const struct software_node *to_software_node(struct fwnode_handle *fwnode); > struct fwnode_handle *software_node_fwnode(const struct software_node *node); > > +const struct software_node * > +software_node_find_by_name(const struct software_node *parent, > + const char *name); > + > int software_node_register_nodes(const struct software_node *nodes); > void software_node_unregister_nodes(const struct software_node *nodes); > > -- > 2.20.1 > -- With Best Regards, Andy Shevchenko
[PATCH 1/3] software node: Add software_node_find_by_name()
Function that searches software nodes by node name. Signed-off-by: Heikki Krogerus --- drivers/base/swnode.c| 35 +++ include/linux/property.h | 4 2 files changed, 39 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index e7b3aa3bd55a..0c4e395e7143 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -620,6 +620,41 @@ 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. + */ +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(_kset->list_lock); + + list_for_each_entry(k, _kset->list, entry) { + swnode = kobj_to_swnode(k); + if (parent == swnode->node->parent && swnode->node->name && + !strcmp(name, swnode->node->name)) { + kobject_get(>kobj); + break; + } + swnode = NULL; + } + + spin_unlock(_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) diff --git a/include/linux/property.h b/include/linux/property.h index 5a910ad79591..9b3d4ca3a73a 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -421,6 +421,10 @@ bool is_software_node(const struct fwnode_handle *fwnode); const struct software_node *to_software_node(struct fwnode_handle *fwnode); struct fwnode_handle *software_node_fwnode(const struct software_node *node); +const struct software_node * +software_node_find_by_name(const struct software_node *parent, + const char *name); + int software_node_register_nodes(const struct software_node *nodes); void software_node_unregister_nodes(const struct software_node *nodes); -- 2.20.1