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 2732A3FE369; Mon, 6 Jul 2026 14:40:00 +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=1783348802; cv=none; b=dMFb0rQ4Ty36pXpYHMy53HOWehyxiY6/eAJsReoHfbJSHhtX36unXFJHWeuweFWsdef49fD/+y/9bzpcuVtUedm8AHPweB+JyG7yMv3fAmPhMDWhFi7i4iMPQ/oyuj/wbigkjFjY99/BA9P8aijieQz3ZMEc361AC5BL76dXyQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783348802; c=relaxed/simple; bh=XtbXxotRn4eonCuXI7S2La3x2DD6roUS8w7lR6Aocns=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=S8YzoJeMQrJYhymBgnF8T9xUST3JdTEI5XOVcy5UwFdxOGntSVyB0Rw3fL6bwQwobVjMr+CEdWXOPnqLJwBeopU9vEKTY8+sHoWtT/ubsriKu9L/a4mmKYBhmR7PTV+D+fDoeOpAkA5TmulzfmSVTxszB/TCOZR3Up8PEPYLHKw= 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=OIh2q5No; 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="OIh2q5No" Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.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 4gv6TB3Q84zKv2g; Mon, 06 Jul 2026 16:39:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1783348798; 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=OIh2q5NoOb8/zfHzXHh6+EFxzLMaDkzPcbVgv5xkovZYR/4JA9SFzE0VU9VAm1rNRZLR0S AX9n6t6Qdg/BHwG8GIE0XsFgInmrRdJCk1rI7C64cKOlIyq4TCeFWdyPovr+dbaBZvE7Xw 3Gt8jIfDUCNo/K6k+YRQVDybeevZzGh0XtuQ2zVUtN5hCMOWCq8qaO0uMb1bLR1G0foLqN KuGMynijGMoLzFJiCQ/pxQVYlrrpwux9nHY20wk2i5B2W/3iVCLsdvpCsubihHUwhDMw1G ARSB7sTYnBnOH85aXuiUq7w/RlmGL22TeStMe6dbMo/bP0D6ZZw0KkWwo9maXg== 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: driver-core@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MBO-RS-ID: dd8ce0f1dac3e9f612a 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);