From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388195; b=dHXfVsz4WRfAw33DSUmYuQPKmYExlZZ57A4S+nWNZkvL3BK/5YIov4MP0r3RL89X8gZ1 sadtFui8zegxygkqHOA6kAkpqaiHsGvo4yA6wHyz5BEEauubUfnXIIZM5MKWq6wbnVPba mGnRfo12iJRQ2rILvbhBPS53ZwQkpHgHW+/PHP9pfTKL9zav8hPoUqfvPEgxK6i8i8Gdd /s/Q6Pu7M0gSXrkNIur24JlqqFMz0gcy4AsJw15mg8olBQ9DLdtX4Gk3yBDkVx3ARSV1A GbyvkH4vNZX5GwV+BwL2/AfW07TTBgzVu48Q/2Du5jSYugqveMxdja6K/fn6ZyVXqwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388195; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=MrhSSDloXsO6oPb5zFgkaIqw0O+cy5fZDJpQxq4S8Fw=; b=LJbkTpx+r/6TXAPx7+IcDpCaopk53VdpZYpHKIBh7go3yJ9U1biC+FR4esLM1OSeyEF5 c92SAKJogMwCOt8UPP2tvv2T2fTh1lrkBh28038xrXvcL/Pg8rtZZlOeEgQjbTIHeQsuf p53hT3irnecPZkDReDD0e6IPkPfNjGfGMMLPd6qToSGs1CU7Yf8inxyYG6sI1Mack6jJ/ f5i5YPc4Pe65DeAX9cJwMR3D1TS9czZYQv1I7vwC+7/piXv24mg7CfDmAQDfpvB5big2g 4EIF6jg78lnZP6f60+e+AsH7VRAC2lf0ypSsfrAwSTCS8tdXk0To5GJCBn6404faC3Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UywEevAa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7324C606A32D; Fri, 4 Dec 2026 12:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UywEevAa Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3E9F1F000C2; Fri, 4 Dec 2026 12:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388195; bh=MrhSSDloXsO6oPb5zFgkaIqw0O+cy5fZDJpQxq4S8Fw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UywEevAa+/c75J+Cjlpuazzl3fhIESqXME+QD/D2ZCwAFMQRs/gM5nAg47A8gxXw4 rhzyPJ9y6iy5IFdldbO004svgSo7EMZHF0kc7B7Rl6eotI+zMxCFG23O0DNrC+SCWW AmItYvGIQNTepH8gEH1OhtV3R8+sQDvAgt1RUi7Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Balasubramani Vivekanandan , Bartosz Golaszewski , Heikki Krogerus , Johan Hovold Subject: [PATCH 6.1 0520/1059] software node: only let the owner release a managed node Date: Fri, 4 Dec 2026 19:00:51 +0900 Message-ID: <20261204100657.703930403@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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); @@ -1110,7 +1111,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)) @@ -1154,7 +1155,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); }