UPSTREAM: software node: Fix device_add_software_node()
The function device_add_software_node() was meant to register the node supplied to it, but only if that node wasn't already registered. Right now the function attempts to always register the node. That will cause a failure with nodes that are already registered. Fixing that by incrementing the reference count of the nodes that have already been registered, and only registering the new nodes. Also, clarifying the behaviour in the function documentation. Fixes: e68d0119e328 ("software node: Introduce device_add_software_node()") Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> (cherry picked from commit 2a92c90f2ecca4475d6050f2f938a1755a8954cc) Bug: 187129171 Signed-off-by: Connor O'Brien <connoro@google.com> Change-Id: I77cb04fd58bfba05622ca8f4264ea45565529049
This commit is contained in:

committed by
Connor O'Brien

parent
4378c305d9
commit
96fd9e07c0
@@ -866,25 +866,33 @@ EXPORT_SYMBOL_GPL(fwnode_remove_software_node);
|
||||
/**
|
||||
* device_add_software_node - Assign software node to a device
|
||||
* @dev: The device the software node is meant for.
|
||||
* @swnode: The software node.
|
||||
* @node: The software node.
|
||||
*
|
||||
* This function will register @swnode and make it the secondary firmware node
|
||||
* pointer of @dev. If @dev has no primary node, then @swnode will become the primary
|
||||
* node.
|
||||
* This function will make @node the secondary firmware node pointer of @dev. If
|
||||
* @dev has no primary node, then @node will become the primary node. The
|
||||
* function will register @node automatically if it wasn't already registered.
|
||||
*/
|
||||
int device_add_software_node(struct device *dev, const struct software_node *swnode)
|
||||
int device_add_software_node(struct device *dev, const struct software_node *node)
|
||||
{
|
||||
struct swnode *swnode;
|
||||
int ret;
|
||||
|
||||
/* Only one software node per device. */
|
||||
if (dev_to_swnode(dev))
|
||||
return -EBUSY;
|
||||
|
||||
ret = software_node_register(swnode);
|
||||
if (ret)
|
||||
return ret;
|
||||
swnode = software_node_to_swnode(node);
|
||||
if (swnode) {
|
||||
kobject_get(&swnode->kobj);
|
||||
} else {
|
||||
ret = software_node_register(node);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
set_secondary_fwnode(dev, software_node_fwnode(swnode));
|
||||
swnode = software_node_to_swnode(node);
|
||||
}
|
||||
|
||||
set_secondary_fwnode(dev, &swnode->fwnode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -488,7 +488,7 @@ fwnode_create_software_node(const struct property_entry *properties,
|
||||
const struct fwnode_handle *parent);
|
||||
void fwnode_remove_software_node(struct fwnode_handle *fwnode);
|
||||
|
||||
int device_add_software_node(struct device *dev, const struct software_node *swnode);
|
||||
int device_add_software_node(struct device *dev, const struct software_node *node);
|
||||
void device_remove_software_node(struct device *dev);
|
||||
|
||||
#endif /* _LINUX_PROPERTY_H_ */
|
||||
|
Reference in New Issue
Block a user