From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@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>
Cc: 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,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Andy Shevchenko <andriy.shevchenko@intel.com>
Subject: [PATCH v5 5/7] driver core: platform: remove software node on release()
Date: Tue, 12 May 2026 13:59:27 +0200 [thread overview]
Message-ID: <20260512-swnode-remove-on-dev-unreg-v5-5-0035eff63812@oss.qualcomm.com> (raw)
In-Reply-To: <20260512-swnode-remove-on-dev-unreg-v5-0-0035eff63812@oss.qualcomm.com>
If we pass a software node to a newly created device using struct
platform_device_info, it will not be removed when the device is
released. This may happen when a module creating the device is removed
or on failure in platform_device_add().
When we try to reuse that software node in a subsequent call to
platform_device_register_full(), it will fails with -EBUSY. Add the
missing call to device_remove_software_node() in release path.
In addition to the above change, make sure that we still function
correctly if a software node is used as the primary firmware node.
Fixes: 0fc434bc2c45 ("driver core: platform: allow attaching software nodes when creating devices")
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/base/platform.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index f617e02b171f6e59a3c40504a71f8915a41e8514..d2f40b348f193db842aa7c17c9c41be59a03d35f 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -599,6 +599,7 @@ static void platform_device_release(struct device *dev)
struct platform_object *pa = container_of(dev, struct platform_object,
pdev.dev);
+ device_remove_software_node(dev);
of_node_put(pa->pdev.dev.of_node);
kfree(pa->pdev.dev.platform_data);
kfree(pa->pdev.mfd_cell);
@@ -895,6 +896,16 @@ struct platform_device *platform_device_register_full(const struct platform_devi
pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
}
+ /*
+ * If the primary firmware node is a software node and there's no
+ * secondary firmware node, the primary will be affected by the call
+ * to device_remove_software_node() in platform_device_release() and
+ * its reference count will be dropped by one. Take another reference
+ * here to make it have no effect.
+ */
+ if (is_software_node(pdevinfo->fwnode))
+ fwnode_handle_get(pdevinfo->fwnode);
+
ret = platform_device_add_resources(pdev, pdevinfo->res, pdevinfo->num_res);
if (ret)
goto err;
--
2.47.3
next prev parent reply other threads:[~2026-05-12 12:00 UTC|newest]
Thread overview: 22+ 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-16 3:28 ` Claude review: " Claude Code Review Bot
2026-05-12 11:59 ` [PATCH v5 2/7] driver core: platform: make the swnode check stricter Bartosz Golaszewski
2026-05-16 3:28 ` Claude review: " Claude Code Review Bot
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-13 11:55 ` Bartosz Golaszewski
2026-05-16 3:28 ` Claude review: " Claude Code Review Bot
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
2026-05-16 3:28 ` Claude review: " Claude Code Review Bot
2026-05-12 11:59 ` Bartosz Golaszewski [this message]
2026-05-16 3:28 ` Claude review: driver core: platform: remove software node on release() Claude Code Review Bot
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-16 3:28 ` Claude review: " Claude Code Review Bot
2026-05-12 11:59 ` [PATCH v5 7/7] driver core: platform: tests: add test cases for correct swnode removal Bartosz Golaszewski
2026-05-16 3:28 ` Claude review: " Claude Code Review Bot
2026-05-12 15:07 ` [PATCH v5 0/7] driver core: remove software node from platform devices on device release Danilo Krummrich
2026-05-16 3:28 ` Claude review: " Claude Code Review Bot
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=20260512-swnode-remove-on-dev-unreg-v5-5-0035eff63812@oss.qualcomm.com \
--to=bartosz.golaszewski@oss.qualcomm.com \
--cc=airlied@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=brgl@kernel.org \
--cc=dakr@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