From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 465A13FE369; Mon, 6 Jul 2026 14:39:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.152 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783348776; cv=none; b=noxbZI1nrFuG780WPjI43f+AOHxt2wabmGYDWis5JA6mWxvGtO8yX3OhJTV6bMR7k09CE9x7SFTIAt1lhWScjG/9WLKlstD6aQdYxD1sQqoU5cH1Z6I90H6XZs9tx4qiSztflSoys0sdxp31S7yLpLsIBnAKAb5vbOuybcZ80Ho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783348776; c=relaxed/simple; bh=XtbXxotRn4eonCuXI7S2La3x2DD6roUS8w7lR6Aocns=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=lMdJJ2Iu67n4dpWr9NIE68p82Jgj5lM61GKlchI1pRPAfNOLddcgdu6ZN+qnXc2JSMwfEaPfcMxDaHaYNtd+k5CQ8ld4AaHZgA3gQoi/5A6SRzK3EGVObmBEw3zHyYppObiewBwo9QwOiAdyE2Vo00MMvXAuihGfLhZ38iO3PaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=j5hgDtth; arc=none smtp.client-ip=80.241.56.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="j5hgDtth" Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4gv6Sc3JlwzKrrB; Mon, 06 Jul 2026 16:39:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1783348768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PTWGfLdwlWAV/LMkx8q6n+16+BLtwX+Uw6eFuSY1pwE=; b=j5hgDtthz8XCNdelXgr2Njc2HaTruqIkCO//JWKxiT4W2gEybWyIlcK2aQ1bxIe+BwUJVp sosZFgtgjTYiKegpajhDS7wAQRa5vbGhsdYsOBErEWcCcj6imJ3WhTyng3CLWaw/u/6S/u Ia++ekOByRWNtL6C0p1KPkAMQ78opS9K6p4731SNIh3G/Gtr0smcjJ5LSbWseUhYMLmi5g bSnkIEWLW+D0H8udCi/rtV6GiUxmmd3h/zBT1zxIEz9pUZOsZhePq4tVuE6vy2STKylPsN pNYuSZntPPijS4W0+CuI8ZBjLVluSsSHTtbS9e6dlXfCM6eF2pFoZi1CDk9EnQ== Message-ID: Subject: Re: [PATCH v3 02/20] driver core: platform: provide platform_device_set_of_node() From: Manuel Ebner To: Bartosz Golaszewski , Lee Jones , Thierry Reding , Sebastian Hesselbarth , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Srinivas Kandagatla , Greg Kroah-Hartman , Vinod Koul , "Rafael J. Wysocki" , Danilo Krummrich , Rob Herring , Saravana Kannan , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Andi Shyti , Andy Shevchenko , Joerg Roedel , Will Deacon , Robin Murphy , Doug Berger , Florian Fainelli , Broadcom internal kernel review list , Ulf Hansson , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Matthew Brost , Thomas =?ISO-8859-1?Q?Hellstr=F6m?= , Rodrigo Vivi , David Airlie , Simona Vetter , Peter Chen , Paul Cercueil , Bin Liu , Philipp Zabel , Maximilian Luz , Hans de Goede , Ilpo =?ISO-8859-1?Q?J=E4rvinen?= , Krzysztof Kozlowski , Benjamin Herrenschmidt Cc: brgl@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-sound@vger.kernel.org, driver-core@lists.linux.dev, devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-i2c@vger.kernel.org, iommu@lists.linux.dev, linux-pm@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-usb@vger.kernel.org, linux-mips@vger.kernel.org, platform-driver-x86@vger.kernel.org, mfd@lists.linux.dev Date: Mon, 06 Jul 2026 16:39:00 +0200 In-Reply-To: <20260706-pdev-fwnode-ref-v3-2-1ff028e33779@oss.qualcomm.com> References: <20260706-pdev-fwnode-ref-v3-0-1ff028e33779@oss.qualcomm.com> <20260706-pdev-fwnode-ref-v3-2-1ff028e33779@oss.qualcomm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MBO-RS-ID: ca569d00ad7df478929 X-MBO-RS-META: 1q71yutefcf1nyjzwoom4gu47fi8rss3 Hi Bartosz, On Mon, 2026-07-06 at 14:44 +0200, Bartosz Golaszewski wrote: > Encapsulate the reference counting logic for OF nodes assigned to > platform devices created with platform_device_alloc() in a helper > function. Make the kerneldoc state that this is the proper interface for > assigning OF nodes to dynamically allocated platform devices. This will > allow us to switch to counting the references of the device's firmware > nodes, not only the OF nodes. >=20 > Reviewed-by: Manuel Ebner > Reviewed-by: Andy Shevchenko > Signed-off-by: Bartosz Golaszewski > --- > =C2=A0drivers/base/platform.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 | 18 ++++++++++++++++++ > =C2=A0include/linux/platform_device.h |=C2=A0 4 ++++ > =C2=A02 files changed, 22 insertions(+) >=20 > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > index fb9120b0bcfe0e7dd9dfc0d29b91e0ad40a01440..3188d5aba5f90622f821c6950= 49cacda030204fb > 100644 > --- a/drivers/base/platform.c > +++ b/drivers/base/platform.c > @@ -693,6 +693,24 @@ int platform_device_add_data(struct platform_device = *pdev, const > void *data, > =C2=A0} > =C2=A0EXPORT_SYMBOL_GPL(platform_device_add_data); > =C2=A0 > +/** > + * platform_device_set_of_node - assign an OF node to device > + * @pdev: platform device to add the node for > + * @np: new device node > + * > + * Assign an OF node to this platform device. Internally keep track of t= he > + * reference count. Devices created with platform_device_alloc() must us= e this > + * function instead of assigning the node manually. I did some more pondering about this patch and concluded the right place for a warning would be the lines been read right before or after assigning a node manually.=20 I think this would be in platform_device_alloc() (as I suggested in v2). BUT my knowledge in C isn't sound. So if it's good as is keep it. If it isn= 't add or move the remark. Either way Thanks and Reviewed-by Manuel Ebner. --- Note: I removed Mark Brown from recipients = because: =E2=80=9CRCPT TO failed: : Recipient address rejected: Domain n= ot found=E2=80=9D. > + */ > +void platform_device_set_of_node(struct platform_device *pdev, > + struct device_node *np) > +{ > + of_node_put(pdev->dev.of_node); > + pdev->dev.of_node =3D of_node_get(np); > + pdev->dev.fwnode =3D of_fwnode_handle(np); > +} > +EXPORT_SYMBOL_GPL(platform_device_set_of_node); > + > =C2=A0/** > =C2=A0 * platform_device_add - add a platform device to device hierarchy > =C2=A0 * @pdev: platform device we're adding > diff --git a/include/linux/platform_device.h b/include/linux/platform_dev= ice.h > index 8c566f09d04efe420d85ffa046f92c44c6d08526..e9f7baceeb4c8269dbc0143c4= d8fc9d73ba024ca > 100644 > --- a/include/linux/platform_device.h > +++ b/include/linux/platform_device.h > @@ -19,6 +19,8 @@ > =C2=A0struct irq_affinity; > =C2=A0struct mfd_cell; > =C2=A0struct property_entry; > +struct platform_device_id; > +struct device_node; > =C2=A0 > =C2=A0struct platform_device { > =C2=A0 const char *name; > @@ -262,6 +264,8 @@ extern int platform_device_add_resources(struct platf= orm_device > *pdev, > =C2=A0 unsigned int num); > =C2=A0extern int platform_device_add_data(struct platform_device *pdev, > =C2=A0 =C2=A0=C2=A0=C2=A0 const void *data, size_t size); > +void platform_device_set_of_node(struct platform_device *pdev, > + struct device_node *np); > =C2=A0extern int platform_device_add(struct platform_device *pdev); > =C2=A0extern void platform_device_del(struct platform_device *pdev); > =C2=A0extern void platform_device_put(struct platform_device *pdev);