UPSTREAM: software node: Handle software node injection to an existing device properly
The function software_node_notify() - the function that creates and removes the symlinks between the node and the device - was called unconditionally in device_add_software_node() and device_remove_software_node(), but it needs to be called in those functions only in the special case where the node is added to a device that has already been registered. This fixes NULL pointer dereference that happens if device_remove_software_node() is used with device that was never registered. Fixes: b622b24519f5 ("software node: Allow node addition to already existing device") Reported-and-tested-by: Dominik Brodowski <linux@dominikbrodowski.net> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> (cherry picked from commit 5dca69e26fe97f17d4a6cbd6872103c868577b14) Bug: 187129171 Signed-off-by: Connor O'Brien <connoro@google.com> Change-Id: I1caca7eaaf76e9b6e48151cecf2219743690ba93
This commit is contained in:

committed by
Connor O'Brien

parent
2f34733fae
commit
2f13bd8f39
@@ -893,6 +893,14 @@ int device_add_software_node(struct device *dev, const struct software_node *nod
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_secondary_fwnode(dev, &swnode->fwnode);
|
set_secondary_fwnode(dev, &swnode->fwnode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the device has been fully registered by the time this function is
|
||||||
|
* called, software_node_notify() must be called separately so that the
|
||||||
|
* symlinks get created and the reference count of the node is kept in
|
||||||
|
* balance.
|
||||||
|
*/
|
||||||
|
if (device_is_registered(dev))
|
||||||
software_node_notify(dev, KOBJ_ADD);
|
software_node_notify(dev, KOBJ_ADD);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -913,6 +921,7 @@ void device_remove_software_node(struct device *dev)
|
|||||||
if (!swnode)
|
if (!swnode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (device_is_registered(dev))
|
||||||
software_node_notify(dev, KOBJ_REMOVE);
|
software_node_notify(dev, KOBJ_REMOVE);
|
||||||
set_secondary_fwnode(dev, NULL);
|
set_secondary_fwnode(dev, NULL);
|
||||||
kobject_put(&swnode->kobj);
|
kobject_put(&swnode->kobj);
|
||||||
@@ -930,8 +939,7 @@ int software_node_notify(struct device *dev, unsigned long action)
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case KOBJ_ADD:
|
case KOBJ_ADD:
|
||||||
ret = sysfs_create_link_nowarn(&dev->kobj, &swnode->kobj,
|
ret = sysfs_create_link(&dev->kobj, &swnode->kobj, "software_node");
|
||||||
"software_node");
|
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user