5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bartosz Golaszewski commit f8623ce596492d2e96ca57eeec992938d3d79f00 upstream. device_create_managed_software_node() creates a node whose lifetime is tied to the device it was created for. software_node_notify_remove() is called for every device that has the node as its fwnode (primary OR secondary) and, if the node is managed, unconditionally detaches it from that device and drops the creation reference. This breaks when the node is shared with another device. Example: the i2c-designware copies the parent's fwnode to the adapter's struct device. When the adapter is deleted, it releases the reference that belongs to the owner and the latter ends up with a dangling pointer. Record the device's "manager" and only perform the actual release when notify is called for that "owner" device. Note that it was never the intention that managed software nodes would be shared, but descendants reusing ancestor firmware nodes is not uncommon and such use is hard to predict when allocating software nodes. Reported-by: Balasubramani Vivekanandan Closes: https://lore.kernel.org/all/20261009164241.923756-2-balasubramani.vivekanandan@intel.com/ Fixes: 151f6ff78cdf ("software node: Provide replacement for device_add_properties()") Signed-off-by: Bartosz Golaszewski Fixes: 0f485f88656a ("drm/xe/i2c: use device_create_managed_software_node()") Reviewed-by: Balasubramani Vivekanandan Tested-by: Balasubramani Vivekanandan Reviewed-by: Heikki Krogerus Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261102-swnode-only-owner-release-v1-1-ee4c9022a629@oss.qualcomm.com [ johan: drop temporary variable; skip clearing owner field; mention reuse not intended in commit message ] Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/base/swnode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -18,6 +18,8 @@ struct swnode { struct fwnode_handle fwnode; const struct software_node *node; int id; + /* Device the managed node's lifetime is tied to. */ + struct device *owner; /* hierarchy */ struct ida child_ids; @@ -26,7 +28,6 @@ struct swnode { struct swnode *parent; unsigned int allocated:1; - unsigned int managed:1; }; static DEFINE_IDA(swnode_root_ids); @@ -1116,7 +1117,7 @@ int device_create_managed_software_node( if (IS_ERR(fwnode)) return PTR_ERR(fwnode); - to_swnode(fwnode)->managed = true; + to_swnode(fwnode)->owner = dev; set_secondary_fwnode(dev, fwnode); if (device_is_registered(dev)) @@ -1160,7 +1161,7 @@ void software_node_notify_remove(struct sysfs_remove_link(&dev->kobj, "software_node"); kobject_put(&swnode->kobj); - if (swnode->managed) { + if (swnode->owner == dev) { set_secondary_fwnode(dev, NULL); kobject_put(&swnode->kobj); }