From: "Danilo Krummrich" <dakr@kernel.org>
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Maximilian Luz" <luzmaximilian@gmail.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
brgl@kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, platform-driver-x86@vger.kernel.org,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 4/7] drm/xe/i2c: use platform_device_add_software_node()
Date: Tue, 12 May 2026 18:24:41 +0200 [thread overview]
Message-ID: <DIGU67TAWF7W.1DWZMO4XAVK7G@kernel.org> (raw)
In-Reply-To: <20260512-swnode-remove-on-dev-unreg-v5-4-0035eff63812@oss.qualcomm.com>
On Tue May 12, 2026 at 1:59 PM CEST, Bartosz Golaszewski wrote:
> diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c
> index 706783863d07d66b4685005d6649b3cd143ecc3b..7f4295e7dc74f112abff8427485b5c8a5ad71383 100644
> --- a/drivers/gpu/drm/xe/xe_i2c.c
> +++ b/drivers/gpu/drm/xe/xe_i2c.c
> @@ -53,6 +53,10 @@ static const struct property_entry xe_i2c_adapter_properties[] = {
> { }
> };
>
> +static const struct software_node xe_i2c_adapter_swnode = {
> + .properties = xe_i2c_adapter_properties,
> +};
> +
> static inline void xe_i2c_read_endpoint(struct xe_mmio *mmio, void *ep)
> {
> u32 *val = ep;
> @@ -96,10 +100,6 @@ static int xe_i2c_register_adapter(struct xe_i2c *i2c)
> struct fwnode_handle *fwnode;
> int ret;
>
> - fwnode = fwnode_create_software_node(xe_i2c_adapter_properties, NULL);
> - if (IS_ERR(fwnode))
> - return PTR_ERR(fwnode);
> -
> /*
> * Not using platform_device_register_full() here because we don't have
> * a handle to the platform_device before it returns. xe_i2c_notifier()
> @@ -107,10 +107,12 @@ static int xe_i2c_register_adapter(struct xe_i2c *i2c)
> * platform_device_register_full() is done.
> */
> pdev = platform_device_alloc(adapter_name, pci_dev_id(pci));
> - if (!pdev) {
> - ret = -ENOMEM;
> - goto err_fwnode_remove;
> - }
> + if (!pdev)
> + return -ENOMEM;
> +
> + ret = platform_device_add_software_node(pdev, &xe_i2c_adapter_swnode);
By calling platform_device_add_software_node() the platform device technically
takes ownership of the struct software_node managing its lifetime, by removing
it in release().
However, this is not properly reflected by the
platform_device_add_software_node() API, as it just stores the pointer given by
the driver, which in this case is a pointer to module memory.
The platform device is reference counted and can outlive the module.
So, I think analogous to platform_device_add_data() we need to make a copy of
the struct software_node in platform_device_add_software_node().
> + if (ret)
> + goto err_pdev_put;
>
> if (i2c->adapter_irq) {
> struct resource res;
> @@ -123,7 +125,6 @@ static int xe_i2c_register_adapter(struct xe_i2c *i2c)
> }
>
> pdev->dev.parent = i2c->drm_dev;
> - pdev->dev.fwnode = fwnode;
> i2c->adapter_node = fwnode;
> i2c->pdev = pdev;
>
> @@ -135,8 +136,6 @@ static int xe_i2c_register_adapter(struct xe_i2c *i2c)
>
> err_pdev_put:
> platform_device_put(pdev);
> -err_fwnode_remove:
> - fwnode_remove_software_node(fwnode);
There is another call to this in xe_i2c_unregister_adapter(), which I think was
missed.
next prev parent reply other threads:[~2026-05-12 16:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 11:59 [PATCH v5 0/7] driver core: remove software node from platform devices on device release Bartosz Golaszewski
2026-05-12 11:59 ` [PATCH v5 1/7] platform/surface: gpe: use platform_device_register_full() Bartosz Golaszewski
2026-05-12 11:59 ` [PATCH v5 2/7] driver core: platform: make the swnode check stricter Bartosz Golaszewski
2026-05-12 11:59 ` [PATCH v5 3/7] driver core: platform: provide platform_device_add_software_node() Bartosz Golaszewski
2026-05-12 16:31 ` Danilo Krummrich
2026-05-12 18:15 ` Dmitry Torokhov
2026-05-12 11:59 ` [PATCH v5 4/7] drm/xe/i2c: use platform_device_add_software_node() Bartosz Golaszewski
2026-05-12 16:24 ` Danilo Krummrich [this message]
2026-05-12 11:59 ` [PATCH v5 5/7] driver core: platform: remove software node on release() Bartosz Golaszewski
2026-05-12 11:59 ` [PATCH v5 6/7] kunit: provide kunit_software_node_register() Bartosz Golaszewski
2026-05-12 15:28 ` Andy Shevchenko
2026-05-12 11:59 ` [PATCH v5 7/7] driver core: platform: tests: add test cases for correct swnode removal Bartosz Golaszewski
2026-05-12 15:07 ` [PATCH v5 0/7] driver core: remove software node from platform devices on device release Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DIGU67TAWF7W.1DWZMO4XAVK7G@kernel.org \
--to=dakr@kernel.org \
--cc=airlied@gmail.com \
--cc=andy@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=brendan.higgins@linux.dev \
--cc=brgl@kernel.org \
--cc=david@davidgow.net \
--cc=dmitry.torokhov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luzmaximilian@gmail.com \
--cc=matthew.brost@intel.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=raemoar63@gmail.com \
--cc=rafael@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox