Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] Unmanaged 'faux_device' will be leaked if KUnit assertions fail, 
leaving a dangling sysfs device.
--

commit 55011cc21a49b0f659a9ade7e86087adb7a9989c
Author: Shixiong Ou <[email protected]>

drm/sched: Create faux device for KUnit tests

This commit updates the DRM scheduler KUnit tests to use a faux device
instead of passing a NULL device pointer to the scheduler initialization.
This prevents a NULL pointer dereference in the drm_sched_job trace event
which expects a valid device pointer.

> diff --git a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c 
> b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
> index 8e9ae7d980eb2..b6954224254e0 100644
> --- a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
> +++ b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c
[ ... ]
> @@ -297,11 +301,20 @@ struct drm_mock_scheduler *drm_mock_sched_new(struct 
> kunit *test, long timeout)
>               .name           = "drm-mock-scheduler",
>       };
>       struct drm_mock_scheduler *sched;
> +     char name[64];
>       int ret;
>  
>       sched = kunit_kzalloc(test, sizeof(*sched), GFP_KERNEL);
>       KUNIT_ASSERT_NOT_NULL(test, sched);
>  
> +     snprintf(name, sizeof(name), "drm-mock-scheduler-%d",
> +              atomic_inc_return(&drm_mock_sched_instance));
> +
> +     sched->faux_dev = faux_device_create(name, NULL, NULL);
> +     KUNIT_ASSERT_NOT_NULL(test, sched->faux_dev);
> +
> +     args.dev = &sched->faux_dev->dev;
> +
>       ret = drm_sched_init(&sched->base, &args);
>       KUNIT_ASSERT_EQ(test, ret, 0);

[Severity: Medium]
If drm_sched_init() fails in drm_mock_sched_new(), will this KUNIT_ASSERT_EQ()
abort the test and leak the faux device allocated above?

Since faux_device_create() allocates and registers a device, but the faux_dev
is not directly managed by KUnit (for example, via kunit_add_action), an
assertion failure here would cause the test to exit immediately without calling
faux_device_destroy(). This could lead to a leak of the struct device and its
sysfs registration, leaving stale entries behind on test failures.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to