From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v8 5/5] driver core: platform: tests: add test cases for correct swnode removal
Date: Thu, 16 Jul 2026 12:51:11 +0000 [thread overview]
Message-ID: <20260716125112.083E91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716-swnode-remove-on-dev-unreg-v8-5-5c2b8cc38c28@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Failing KUNIT_ASSERT_* macros abort the test early without unregistering the platform device, leaking it and leaving dangling pointers.
- [High] Binding a test-scoped fwnode to a refcounted platform_device leads to a Use-After-Free if the device outlives the test, even on the success path.
- [Low] Missing <kunit/fwnode.h> dependency causes build breakage.
--
--- Patch [5]: [PATCH v8 5/5] driver core: platform: tests: add test cases for correct swnode removal ---
commit 34e0068267b7ef119d11aacf8edb960ce02d5583
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
driver core: platform: tests: add test cases for correct swnode removal
This commit extends the kunit module for platform devices by adding test
cases to verify that the same software node can be added to platform devices
repeatedly.
> diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c
> index 6355a2231b741..9ce563f76aad6 100644
> --- a/drivers/base/test/platform-device-test.c
> +++ b/drivers/base/test/platform-device-test.c
> @@ -1,12 +1,15 @@
> // SPDX-License-Identifier: GPL-2.0
>
> +#include <kunit/fwnode.h>
[Severity: Low]
This include, and the kunit_software_node_register() function used later in
the test, don't seem to exist in the tree at this point.
Will this cause a build failure?
[ ... ]
> +static void platform_device_swnode_add_twice(struct kunit *test)
> +{
> + struct platform_device_info pdevinfo;
> + struct platform_device *pdev;
> + struct fwnode_handle *fwnode;
> + bool bound = false;
> + int ret;
> +
> + fwnode = kunit_kzalloc(test, sizeof(*fwnode), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fwnode);
> +
> + ret = kunit_platform_driver_register(test, &platform_swnode_test_driver);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + fwnode_init(fwnode, NULL);
> + pdevinfo = (struct platform_device_info){
> + .name = DEVICE_NAME,
> + .id = PLATFORM_DEVID_NONE,
> + .fwnode = fwnode,
> + .swnode = &platform_device_test_swnode,
> + };
> +
> + pdev = platform_device_register_full(&pdevinfo);
[Severity: High]
Since the fwnode is allocated with kunit_kzalloc(), its lifetime is tied
strictly to the test execution. However, platform devices are refcounted, and
platform_device_unregister() only drops a reference count.
If the final platform_device_release() is delayed (for example, by external
subsystems holding references), and the test finishes in the meantime, the
fwnode memory will be freed early.
When the delayed release finally executes, it checks
is_software_node(dev_fwnode(dev)). Does this result in a use-after-free on
the kunit-managed fwnode pointer?
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
> +
> + wait_for_device_probe();
> + scoped_guard(device, &pdev->dev)
> + bound = device_is_bound(&pdev->dev);
> +
> + KUNIT_ASSERT_TRUE(test, bound);
[Severity: High]
If this assertion fails, KUNIT_ASSERT_TRUE will abort the test immediately and
skip the subsequent platform_device_unregister(pdev) call.
Since the platform device was registered globally, does an assertion failure
here permanently leak the device and leave it pointing to test-scoped memory
after the test exits?
[ ... ]
> +static void platform_device_two_swnodes(struct kunit *test)
> +{
> + static const struct property_entry properties[] = {
> + PROPERTY_ENTRY_U32("foo", 42),
> + { }
> + };
> +
> + struct platform_device_info pdevinfo;
> + struct platform_device *pdev;
> + struct fwnode_handle *fwnode;
> + int ret;
> +
> + ret = kunit_platform_driver_register(test, &platform_swnode_test_driver);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + fwnode = kunit_software_node_register(test, &platform_device_test_swnode);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fwnode);
> +
> + pdevinfo = (struct platform_device_info){
> + .name = DEVICE_NAME,
> + .id = PLATFORM_DEVID_NONE,
> + .fwnode = fwnode,
> + .swnode = &platform_device_test_swnode,
> + };
> +
> + pdev = platform_device_register_full(&pdevinfo);
> + KUNIT_ASSERT_TRUE(test, IS_ERR(pdev));
[Severity: High]
If the invalid device registration surprisingly succeeds, this assertion will
fail and abort the test without unregistering the newly created device.
Could this permanently leak the platform device if the test fails?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716-swnode-remove-on-dev-unreg-v8-0-5c2b8cc38c28@oss.qualcomm.com?part=5
next prev parent reply other threads:[~2026-07-16 12:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 12:31 [PATCH v8 0/5] driver core: unify the release path for dynamically allocated platform devices Bartosz Golaszewski
2026-07-16 12:31 ` [PATCH v8 1/5] driver core: platform: amend the API contract for fwnode setters Bartosz Golaszewski
2026-07-16 12:39 ` sashiko-bot
2026-07-17 11:29 ` Danilo Krummrich
2026-07-16 12:31 ` [PATCH v8 2/5] platform/surface: gpe: use platform_device_register_full() Bartosz Golaszewski
2026-07-16 12:31 ` [PATCH v8 3/5] drm/xe/i2c: use device_create_managed_software_node() Bartosz Golaszewski
2026-07-16 12:31 ` [PATCH v8 4/5] driver core: platform: unify release path Bartosz Golaszewski
2026-07-16 13:02 ` sashiko-bot
2026-07-16 12:31 ` [PATCH v8 5/5] driver core: platform: tests: add test cases for correct swnode removal Bartosz Golaszewski
2026-07-16 12:51 ` sashiko-bot [this message]
2026-07-19 23:08 ` [PATCH v8 0/5] driver core: unify the release path for dynamically allocated platform devices 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=20260716125112.083E91F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.