From: Stuart Summers <stuart.summers@intel.com>
Cc: driver-core@lists.linux.dev,
bartosz.golaszewski@oss.qualcomm.com,
balasubramani.vivekanandan@intel.com,
intel-xe@lists.freedesktop.org, heikki.krogerus@linux.intel.com,
dakr@kernel.org, andriy.shevchenko@linux.intel.com,
Stuart Summers <stuart.summers@intel.com>
Subject: [PATCH] driver core: platform: tests: add a shared software node test case
Date: Wed, 4 Nov 2026 20:24:16 +0000 [thread overview]
Message-ID: <20261104202419.30180-2-stuart.summers@intel.com> (raw)
Cover the pattern used by drm/xe + i2c-designware, where a software node
assigned as a platform device's primary firmware node is handed to a
second device via device_set_node(), and make sure removing that second
device leaves the owner's node intact.
A potential fix for this issue in the drm/xe driver is being discussed
in [1].
The signature in this case looks like this:
Oops: general protection fault, probably for non-canonical address
0x6b6b6b6b6b6b6b73
RIP: platform_device_release+0x6f/0x80
Signed-off-by: Stuart Summers <stuart.summers@intel.com>
Assisted-by: LLM
[1]: https://patchwork.freedesktop.org/series/175858/
---
drivers/base/test/platform-device-test.c | 57 ++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c
index 9ce563f76aad..378ba7fab2ac 100644
--- a/drivers/base/test/platform-device-test.c
+++ b/drivers/base/test/platform-device-test.c
@@ -420,9 +420,66 @@ static void platform_device_two_swnodes(struct kunit *test)
"Expected errno == -EINVAL, got: %pe", pdev);
}
+static void platform_device_swnode_sharer_release(struct device *dev)
+{
+}
+
+/*
+ * A software node assigned as a platform device's primary firmware node may be
+ * shared with other devices: i2c-designware passes dev_fwnode() of its platform
+ * device down to the i2c adapter device it creates. Check that removing the
+ * sharing device leaves the owner's software node intact.
+ */
+static void platform_device_swnode_shared(struct kunit *test)
+{
+ static const struct property_entry properties[] = {
+ PROPERTY_ENTRY_STRING("compatible", "test,shared-swnode"),
+ { }
+ };
+ struct fwnode_handle *fwnode;
+ struct platform_device *pdev;
+ struct device *shared;
+ int ret;
+
+ pdev = platform_device_alloc(DEVICE_NAME, PLATFORM_DEVID_NONE);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
+
+ fwnode = fwnode_create_software_node(properties, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fwnode);
+ platform_device_set_fwnode(pdev, fwnode);
+
+ ret = platform_device_add(pdev);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ /*
+ * A second, non-platform device referencing the same fwnode, like the
+ * i2c adapter device created by i2c-designware.
+ */
+ shared = kunit_kzalloc(test, sizeof(*shared), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, shared);
+
+ device_initialize(shared);
+ shared->release = platform_device_swnode_sharer_release;
+ ret = dev_set_name(shared, "test-swnode-sharer");
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ device_set_node(shared, dev_fwnode(&pdev->dev));
+
+ ret = device_add(shared);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ device_unregister(shared);
+
+ /* The owner must still have its software node. */
+ KUNIT_EXPECT_PTR_EQ(test, dev_fwnode(&pdev->dev), fwnode);
+
+ platform_device_unregister(pdev);
+ fwnode_remove_software_node(fwnode);
+}
+
static struct kunit_case platform_device_swnode_tests[] = {
KUNIT_CASE(platform_device_swnode_add_twice),
KUNIT_CASE(platform_device_swnode_as_primary),
+ KUNIT_CASE(platform_device_swnode_shared),
KUNIT_CASE(platform_device_two_swnodes),
{}
};
--
2.43.0
next reply other threads:[~2026-11-04 20:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 20:24 Stuart Summers [this message]
2026-11-04 20:58 ` ✗ CI.checkpatch: warning for driver core: platform: tests: add a shared software node test case Patchwork
2026-11-04 20:59 ` Summers, Stuart
2026-11-04 21:00 ` ✓ CI.KUnit: success " Patchwork
2026-11-04 21:34 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-04 22:04 ` [PATCH] " Andy Shevchenko
2026-11-04 22:51 ` Summers, Stuart
2026-11-05 5:11 ` ✗ CI.checkpatch: warning for driver core: platform: tests: add a shared software node test case (rev2) Patchwork
2026-11-05 5:13 ` ✓ CI.KUnit: success " Patchwork
2026-11-05 5:48 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-05 20:42 ` ✗ Xe.CI.FULL: failure " Patchwork
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=20261104202419.30180-2-stuart.summers@intel.com \
--to=stuart.summers@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=balasubramani.vivekanandan@intel.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=heikki.krogerus@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
/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