Commit 7764c62f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'devprop-5.13-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull device properties framework fix from Rafael Wysocki:
 "Fix a NULL pointer dereference introduced by a recent commit and
  occurring when device_remove_software_node() is used with a device
  that has never been registered (Heikki Krogerus)"

* tag 'devprop-5.13-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
  software node: Handle software node injection to an existing device properly
parents b960e014 5dca69e2
...@@ -1045,7 +1045,15 @@ int device_add_software_node(struct device *dev, const struct software_node *nod ...@@ -1045,7 +1045,15 @@ 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);
software_node_notify(dev, KOBJ_ADD);
/*
* 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);
return 0; return 0;
} }
...@@ -1065,7 +1073,8 @@ void device_remove_software_node(struct device *dev) ...@@ -1065,7 +1073,8 @@ void device_remove_software_node(struct device *dev)
if (!swnode) if (!swnode)
return; return;
software_node_notify(dev, KOBJ_REMOVE); if (device_is_registered(dev))
software_node_notify(dev, KOBJ_REMOVE);
set_secondary_fwnode(dev, NULL); set_secondary_fwnode(dev, NULL);
kobject_put(&swnode->kobj); kobject_put(&swnode->kobj);
} }
...@@ -1119,8 +1128,7 @@ int software_node_notify(struct device *dev, unsigned long action) ...@@ -1119,8 +1128,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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment