From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D88C3AC0DC for ; Thu, 3 Sep 2026 09:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788428190; cv=none; b=jJY4x/plSfif+iilGXMMXTNlkAXBtbmDQC3rk/81rg1/viGRKRy8JjxaIBdcROqg2mq5eTsLOppAoLJ32O34qaU7L9M/lLQHUV/zhH+6L1qZJP3NpcAMRjDo5gVJ/J7jnyN9d3sqbSUnoErkY5jiRi5VXGAGZZAtgjwy5nXV9TY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788428190; c=relaxed/simple; bh=Q8LghgCE/zgIXQhozr/WYjRrR9/ZvNYImG1MfSyFxnI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BqEtBu+TX78ngigetkN1KDBjMt5FridJl4KV/JXqIGQcvMgWWeGP6BJD0M0wC3/wdHsUCfCJjX92Jn0EaUijFEka04nAOf/6NQjWCipH92fZe+DFnmRVO6hMpOvxepLoiyqsmQ21UAmCMUDYnmHv0XCoRoeJ5wwfHa1YgQFyyXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O6GCz86u; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O6GCz86u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 779821F000E9; Thu, 3 Sep 2026 09:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788428189; bh=eEVXzclCY3N/gsaKYs1NrOcPH/+3yo1KDKKfVvSeYqQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=O6GCz86uTNsnRwq4BI0UdNM+4FoZnpEKT+zkv92LME7ynDS5sHLRu08zO5EfJ1tCc HiH5V6UvjPm+RajqcS0u7X1HrRczMhfLqyM40Wuq7FAkDJV9YlrsSQkbYBjxFHtWsB mivZjEwuEg5jY7wuwpEt9Sl8LiX9iWG3nzXrO7cKqEsygl4ajmbQ3HrGTFXcex9/x7 dwvUSlNm97bpZw831VTpYZ8yR65zd93GEhLCEGfow34BWYv8Nl3j56hClnF7vB3jxU nvykuzHi4B8soBC+tTf7ZYD8zDKmYozNSai/DUKFMcunjNBJZv/qf3LBDqeRuGMxL5 3hXNCL8xkGpVA== Date: Thu, 3 Sep 2026 11:36:25 +0200 From: Maxime Ripard To: oushixiong1025@163.com Cc: Matthew Brost , Danilo Krummrich , Philipp Stanner , Christian =?utf-8?B?S8O2bmln?= , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Shixiong Ou Subject: Re: [PATCH RESEND] drm/sched: Create faux device for KUnit tests Message-ID: References: <20260903090256.552317-1-oushixiong1025@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha384; protocol="application/pgp-signature"; boundary="vuulpcyigbnspu6n" Content-Disposition: inline In-Reply-To: <20260903090256.552317-1-oushixiong1025@163.com> --vuulpcyigbnspu6n Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH RESEND] drm/sched: Create faux device for KUnit tests MIME-Version: 1.0 Hi, On Thu, Sep 03, 2026 at 05:02:56PM +0800, oushixiong1025@163.com wrote: > From: Shixiong Ou >=20 > 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. >=20 > 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. >=20 > An atomic counter is used to generate unique device names, since > multiple mock schedulers can exist simultaneously across different > test suites. >=20 > Signed-off-by: Shixiong Ou > --- > drivers/gpu/drm/scheduler/tests/mock_scheduler.c | 14 ++++++++++++++ > drivers/gpu/drm/scheduler/tests/sched_tests.h | 2 ++ > 2 files changed, 16 insertions(+) >=20 > diff --git a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c b/drivers/g= pu/drm/scheduler/tests/mock_scheduler.c > index 14403a762335..cd87e405bb1e 100644 > --- a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c > +++ b/drivers/gpu/drm/scheduler/tests/mock_scheduler.c > @@ -1,6 +1,8 @@ > // SPDX-License-Identifier: GPL-2.0 > /* Copyright (c) 2025 Valve Corporation */ > =20 > +#include > + > #include "sched_tests.h" > =20 > /* > @@ -10,6 +12,8 @@ > * Test cases are implemented in a separate file. > */ > =20 > +static atomic_t drm_mock_sched_instance =3D 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(struc= t kunit *test, long timeout) > .name =3D "drm-mock-scheduler", > }; > struct drm_mock_scheduler *sched; > + char name[64]; > int ret; > =20 > sched =3D kunit_kzalloc(test, sizeof(*sched), GFP_KERNEL); > KUNIT_ASSERT_NOT_NULL(test, sched); > =20 > + snprintf(name, sizeof(name), "drm-mock-scheduler-%d", > + atomic_inc_return(&drm_mock_sched_instance)); > + > + sched->faux_dev =3D faux_device_create(name, NULL, NULL); > + KUNIT_ASSERT_NOT_NULL(test, sched->faux_dev); > + > + args.dev =3D &sched->faux_dev->dev; > + > ret =3D drm_sched_init(&sched->base, &args); > KUNIT_ASSERT_EQ(test, ret, 0); > =20 > @@ -323,6 +336,7 @@ struct drm_mock_scheduler *drm_mock_sched_new(struct = kunit *test, long timeout) > void drm_mock_sched_fini(struct drm_mock_scheduler *sched) > { > drm_sched_fini(&sched->base); > + faux_device_destroy(sched->faux_dev); > } What's wrong with drm_kunit_helper_alloc_device(), or kunit_device_register= ()? Maxime --vuulpcyigbnspu6n Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iJUEABMJAB0WIQTkHFbLp4ejekA/qfgnX84Zoj2+dgUCapk/mAAKCRAnX84Zoj2+ dq36AYCmkQLjePG4c0c/9Q7SCXi6p+2rTtN49hAqC27AranW/qxBLY14QxYSbj/F hR7gMnABgLth8E7SzxyPLv4bbgibQbYcBJNMitXrWtmUqq8pFrNiGY/GE58CozHF VjJHgT+tiQ== =g0bm -----END PGP SIGNATURE----- --vuulpcyigbnspu6n--