Re: [PATCH RESEND] drm/sched: Create faux device for KUnit tests
From: Philipp Stanner
Date: Thu Sep 03 2026 - 06:00:18 EST
On Thu, 2026-09-03 at 17:02 +0800, oushixiong1025@xxxxxxx wrote:
> From: Shixiong Ou <oushixiong@xxxxxxxxxx>
>
> The DRM scheduler KUnit tests currently pass NULL for the dev field in
> drm_sched_init_args, which causes a NULL pointer dereference in the
> drm_sched_job trace event when it calls dev_name() on sched->dev.
>
> Use faux_device_create() to create a fake device for the mock scheduler,
> so the scheduler always has a valid device pointer. This avoids the
> trace event crash without requiring the production code to accept a NULL
> device pointer, which conceptually makes no sense for a scheduler.
>
> An atomic counter is used to generate unique device names, since
> multiple mock schedulers can exist simultaneously across different
> test suites.
>
> Signed-off-by: Shixiong Ou <oushixiong@xxxxxxxxxx>
Didn't you address a fault / bug with that?
Cc: stable …
Fixes:
?
> ---
>
[…]
>
> +static atomic_t drm_mock_sched_instance = ATOMIC_INIT(0);
> +
> /**
> * drm_mock_sched_entity_new - Create a new mock scheduler entity
> *
> @@ -296,11 +300,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",
You could use args.name here.
> + atomic_inc_return(&drm_mock_sched_instance));
Couldn't that atomic be a `static unsigned int` inside this function?
Is simpler and limits the scope. And I wouldn't expect that we'll ever
call drm_mock_sched_new() multi-threaded, or would we?
Besides looks cool, thx
P.