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=1796572254; b=Jaj4mC49Dr+xSHRlWJSEeaYC9PJUl1TUadSrdpw1K5wiMXHS4qtlUd7zDQlt3KJVgD6Y gqH1dbkEB3CGGDYE7QlNfzirp3thCoD6OEtTsuvxcPAvhTMc9Zc+3hWmQb6agmQA09iKn FIbbgc2/nwk5KPdVMpo+3SkGDbiWmrJimCw99vRZeEh7xfsjlJGTD7x+8S3+Tuzbl53ED EgP2F2jmev8ZL9XQfbNAWojsjdpNOwrOErV8n19aG++rHy5/le9090ygSGxL/+d723587 llaJ91sJ5+g2JMDmY+oi9BfZ/6tFqagE5XE8rbXnDRr79qylo5fpydmgcK62xCw8MJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796572254; h=Received:DKIM-Signature:Mime-Version:Content-Transfer-Encoding: Content-Type:Date:Message-Id:Subject:Cc:To:From:References: In-Reply-To; bh=6UlWa4XJSNPa7hhalQDGHV24iu8Eiof3ySI6mnqm0qM=; b=4H6nKdxmCj27voXsPB2HQ43HkCrs6nvTBmaMSL+gS86XweCH3jJtXDOo37DmVTQK3x1f 6FafSVF4R/Y5icnZhz/qd1UGU5G2yxQqKkB9tn/zA3w1fPJuvTolMbLXTbfz0+iXRfO28 knvtA3EhK4Ca9U2hV9sszxvL6ABUq+J1HDcI9ct0BaIBm0i6lRYMh7nN7i5uabA/UVKgA yt0jQAdgtONkqdd2qlc1IyWYfG1F4SCSMRjsDhCepVGDRoQ8JNSvtS1lYk03hkjhg32fn 3v6Apr92x3tI2Y/xUsvpTnZbvG+Ylol/s9iNL5Lhfp6p3iZdNOmeBVeZbycYkfnglcA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SssNP3lp; 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 DAC59606A31F; Sun, 6 Dec 2026 15:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SssNP3lp Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA121F0092B; Sun, 6 Dec 2026 15:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796572254; bh=6UlWa4XJSNPa7hhalQDGHV24iu8Eiof3ySI6mnqm0qM=; h=Date:Subject:Cc:To:From:References:In-Reply-To; b=SssNP3lprbuTz6yCTuHbwYuTQN1mMC39UaK+JH8zZli+UJfdvpqlT3Z9k4536zdTe thaqavro6ViYpOCcvirsKE8Q14b4Pcn+hRIhJo9N2LraJyFHprsxCrAWLVRm81Xp3w ex0uJCIHba8u2ydnfccfzdGf82ud3pOWKs2cGi5HL0nesDYTMwkP2bOR82NQNCtXWT W+0NOYasnfh1ouONs9Nt+8xJS1191kIM2zP4mzdd5n3Hgwu86wpFW8ny036yhjYDvF vfI7XQJ5dDSTEzDgkZPIagF0gOtejfju9Co6VzJeMG/jku4hdsVt5qHo2hSgkQ7kUL vukT7Xpqfy/wQ== X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sun, 06 Dec 2026 16:50:50 +0100 Message-Id: Subject: Re: [PATCH 1/3] driver core: swnode: only release owned secondary software nodes Cc: "Greg Kroah-Hartman" , "Rafael J. Wysocki" , "Johan Hovold" , "Andy Shevchenko" , "Daniel Scally" , "Heikki Krogerus" , "Sakari Ailus" , "Bartosz Golaszewski" , , , , To: "Dmitry Torokhov" From: "Danilo Krummrich" References: <20261202-swnode-shared-primary-fix-v1-0-7ff23caaa1ed@gmail.com> <20261202-swnode-shared-primary-fix-v1-1-7ff23caaa1ed@gmail.com> <052097db57228acd881b7684032e7eb0@gmail.com> In-Reply-To: <052097db57228acd881b7684032e7eb0@gmail.com> On Sun Dec 6, 2026 at 8:07 AM CET, Dmitry Torokhov wrote: > Hi Danilo, > > On Sun, Dec 06, 2026 at 12:03:54AM +0100, Danilo Krummrich wrote: >> On Thu Dec 3, 2026 at 2:34 AM CET, Dmitry Torokhov wrote: >> > diff --git a/drivers/base/core.c b/drivers/base/core.c >> > index 44f79f427b6b..673dc5941019 100644 >> > --- a/drivers/base/core.c >> > +++ b/drivers/base/core.c >> > @@ -5250,12 +5250,19 @@ void set_primary_fwnode(struct device *dev, st= ruct fwnode_handle *fwnode) >> > dev->fwnode =3D fwnode; >> > } else { >> > if (fwnode_is_primary(fn)) { >> > - dev->fwnode =3D fn->secondary; >> > - >> > - /* Skip nullifying fn->secondary if the primary is shared */ >> > - if (parent && fn =3D=3D parent->fwnode) >> > + /* >> > + * If the primary fwnode is shared with the parent and >> > + * this device did not attach the secondary node, clear >> > + * dev->fwnode without leaving it pointing to the >> > + * parent's secondary node or modifying fn->secondary. >> > + */ >> > + if (parent && fn =3D=3D parent->fwnode && >> > + !dev_swnode_added(dev)) { >> > + dev->fwnode =3D NULL; >> > return; >> > + } >> >> I think the Sashiko report [1] is valid (though it was present before th= is patch >> as well). >> >> I think we need to preserve the borrowed secondary when detaching a non-= shared >> primary, and ensure device release drops only references the device actu= ally >> owns. >> >> [1] https://sashiko.dev/#/patchset/20261202-swnode-shared-primary-fix-v1= -0-7ff23caaa1ed%40gmail.com > > Right, I agree. set_primary_fwnode(dev, NULL) already preserves the > borrowed secondary when "fn !=3D parent->fwnode", so the gap is in > platform_device_release() and i2c_unregister_device(), which call > fwnode_handle_put(dev_fwnode(dev)) assuming > device_remove_software_node() cleared any secondary node first. > > Before I send v2, which direction do you prefer? > > 1. Track borrowed dev->fwnode pointers with DEV_FLAG_FWNODE_BORROWED and > add device_put_fwnode() in a prep patch (diff below, against the > series base). This also covers ipu-bridge.c and mipi-disco-img.c, > which write primary->secondary directly without ERR_PTR(-ENODEV). > > 2. Move fwnode_is_primary() to include/linux/fwnode.h and guard the put: > > device_remove_software_node(dev); > fwnode =3D dev_fwnode(dev); > if (fwnode_is_primary(fwnode)) > fwnode_handle_put(fwnode); > > Smaller diff, though ipu-bridge.c and mipi-disco-img.c stay exposed > until fixed separately. Those two can't set ERR_PTR(-ENODEV) ahead of > DEV_FLAG_SWNODE_ADDED, since fwnode_is_primary() returning true is > what keeps device_remove_software_node() from dropping their ref. > > I lean toward option 1 since it makes ownership explicit instead of > relying on ERR_PTR(-ENODEV). Yes, I much prefer option 1. One thing to consider, IIUC a sequence of platform_device_set_fwnode(pdev, fwnode); set_primary_fwnode(&pdev->dev, fwnode); would leak the reference acquired by platform_device_set_fwnode() if fwnode= is a primary software node. Obviously, it doesn't make sense to do that, but maybe there are cases wher= e this could still happen through common code paths, subsystem wrappers, etc.= ? I think set_primary_fwnode() should explicitly document its borrowing seman= tics, including that it does not release any reference previously acquired by the caller or another layer. > Longer term it may be worth reworking how primary and secondary fwnodes a= re > stacked and refcounted, though that is beyond a stable fix. I think the relationship between primary and secondary could be improved. Otherwise, I think representing shared ownership, borrowing, and the corresponding lifetimes is simply difficult without help from the compiler.