Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stuart Summers" <stuart.summers@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 1/1] driver core: platform: tests: add a shared software node test case
Date: Wed, 18 Nov 2026 22:49:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-222127@kernel.org> (raw)
In-Reply-To: <20261118223023.19653-4-stuart.summers@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] driver core: test: platform_device_swnode_shared() tests
  unmanaged swnode
- [Low] driver core: test: unsafe device lifetime in
  platform_device_swnode_shared()
--

commit 456e50d0c4a7cd5e70182bbae38d6d777a4710e4
Author: Stuart Summers <stuart.summers@intel.com>

driver core: platform: tests: add a shared software node test case

This commit adds a KUnit test case verifying that sharing a platform
device's software node with a second device via device_set_node() leaves
the owner's software node intact when the second device is unregistered.

Link: https://patchwork.freedesktop.org/series/175858/ [1]

> diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c
> index 9ce563f76aad6..378ba7fab2acf 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);

[Severity: Medium]
Does platform_device_swnode_shared() exercise the managed software node
path that caused the drm/xe + i2c-designware platform_device_release()
use-after-free?

In xe_i2c_register_adapter(), drm/xe attaches the node via
device_create_managed_software_node(&pdev->dev, ...), which sets
swnode->owner = &pdev->dev.  Creating the node with
fwnode_create_software_node() and platform_device_set_fwnode() leaves
swnode->owner as NULL and takes an extra fwnode reference, so
software_node_notify_remove(shared) never reaches the managed-node
release check fixed in f8623ce59649 ("software node: only let the owner
release a managed node"):

drivers/base/swnode.c:software_node_notify_remove() {
    ...
	if (swnode->owner == dev) {
		set_secondary_fwnode(dev, NULL);
		swnode_put(swnode);
	}
}

As written, the test passes even without that fix.

> +
> +	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);

[Severity: Low]
Can allocating shared with kunit_kzalloc() and an empty release callback
cause a use-after-free when CONFIG_DEBUG_KOBJECT_RELEASE=y?

Under CONFIG_DEBUG_KOBJECT_RELEASE=y, device_unregister(shared) ->
put_device() -> kobject_release() schedules shared->kobj.release as
delayed work instead of cleaning up synchronously, so KUnit frees shared
when the test exits while kobject_delayed_cleanup() is still queued.
Also, if any intermediate KUNIT_ASSERT_* fails before the end of the
test, the unmanaged pdev, fwnode and shared allocations and registrations
are leaked.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118223023.19653-3-stuart.summers@intel.com?part=1

      reply	other threads:[~2026-11-18 22:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 22:30 [PATCH 0/1] Add a shared software node test case to driver core Stuart Summers
2026-11-18 22:30 ` [PATCH 1/1] driver core: platform: tests: add a shared software node test case Stuart Summers
2026-11-18 22:49   ` sashiko-bot [this message]

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=sashiko-outbox-222127@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stuart.summers@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