From nobody Fri Sep 25 22:20:16 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 E58DA33120E; Tue, 8 Sep 2026 06:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788847242; cv=none; b=bVwfoOapPDPHq7RuYRg4m3RYxrluWGJCe2Ryv9dKAju6x/r6Ybf2vUBxuaAfyRa1Z7PYinOXFYPtPXjeeR2g2Eh0lcGoHzMhc+9MBWc6zS/a4ssbn1lyXFMttv23ez+VP6eP344ugdvUXNgKieMlGToUi56woQ4FO34ByArIK+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788847242; c=relaxed/simple; bh=ECMEijpuiP02MSLfInysi2EZix0M+5fozPoUASmaT+I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=OdL2cUR2DheGSyck9Jr0JX5/eCyrLfVwCBttztoB2OsEgMLhCaFAbLGe4crhgSaxw5jZ4P+HYM1E+fkxdrZNTZn3oUFOYzvVNG+nAZO1j+2UMIl3kEhraLU9PHHOixV2mKlmRIYY9DCAJhhsmchxU0loL3SDO9zy9ggn0dYMTfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=mP+NOydg; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="mP+NOydg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=1Y Ohb3D73/8SdyecCiPhE4vQmQl1qBOdVYxBb3ICr88=; b=mP+NOydgwCA/j2md0M pdnX7VH0oUSz5zrWzegbQgreh5L1x5Y5Ltgy6svop/x3GyDGtXOCy/vH1F6rRyzu bd6rkkf8O57jsV8EbOUipz9uUSWdL5f5VnVQyOTuEOy5ebjeAgE4vAM3MIuFc/WO Qgxxi/QVM8XeMpEpCMOzww0pc= Received: from localhost.localdomain (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wBHOVhSpJ9qyCC7BQ--.30517S2; Tue, 08 Sep 2026 13:59:47 +0800 (CST) From: oushixiong1025@163.com To: Matthew Brost Cc: Danilo Krummrich , Philipp Stanner , =?UTF-8?q?Christian=20K=C3=B6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Shixiong Ou , stable@vger.kernel.org Subject: [PATCH v4] drm/sched: Create a fake device for KUnit tests Date: Tue, 8 Sep 2026 13:59:41 +0800 Message-Id: <20260908055941.351486-1-oushixiong1025@163.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wBHOVhSpJ9qyCC7BQ--.30517S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFW5ur1fJrW5Cr17WFW3Wrg_yoW5Wr1rpF WkXFWYgrWrtrZFg3y3ua95XFyfGwsrA3yxKr1kX34a9F1qgFyfJr17KrW3t347ArWDZFWS q3Z0gw47Gr4jyw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jnL05UUUUU= X-CM-SenderInfo: xrxvxxx0lr0wirqskqqrwthudrp/xtbC4RO-zmqfpFNyzwAA38 Content-Type: text/plain; charset="utf-8" From: Shixiong Ou The DRM scheduler KUnit tests pass NULL for the dev field in drm_sched_init_args, which NULL-pointer dereferences in the drm_sched_job trace event via dev_name() on sched->dev. Give the mock scheduler a device with kunit_device_register(), which is also cleaned up at test exit. A per-function counter keeps the device names unique, since some tests create several mock schedulers. Fixes: 5a99350794fe ("drm/sched: Add scheduler unit testing infrastructure = and some basic tests") Cc: stable@vger.kernel.org Signed-off-by: Shixiong Ou Acked-by: Maxime Ripard --- v3->v4: - Initialize the instance counter explicitly v2->v3: - Start the mock scheduler device numbering at 0, using instance++ instead of ++instance v1->v2: - Switch from faux_device_create() to kunit_device_register(), which also cleans the device up automatically at test exit (Maxime Ripard) - Build the device name on top of args.name (Philipp Stanner) - Make the instance counter a static unsigned int local to drm_mock_sched_new() (Philipp Stanner) - Add a Fixes: tag and Cc: stable for the NULL dev dereference drivers/gpu/drm/scheduler/tests/mock_scheduler.c | 11 ++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpu/drm/scheduler/tests/mock_scheduler.c b/drivers/gpu= /drm/scheduler/tests/mock_scheduler.c index 8e9ae7d980eb..12dc61f56192 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 /* @@ -288,6 +290,7 @@ static const struct drm_sched_backend_ops drm_mock_sche= duler_ops =3D { */ struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long tim= eout) { + static unsigned int instance =3D 0; struct drm_sched_init_args args =3D { .ops =3D &drm_mock_scheduler_ops, .num_rqs =3D DRM_SCHED_PRIORITY_COUNT, @@ -297,11 +300,19 @@ struct drm_mock_scheduler *drm_mock_sched_new(struct = kunit *test, long timeout) .name =3D "drm-mock-scheduler", }; struct drm_mock_scheduler *sched; + struct device *dev; + 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), "%s-%u", args.name, instance++); + dev =3D kunit_device_register(test, name); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + + args.dev =3D dev; + ret =3D drm_sched_init(&sched->base, &args); KUNIT_ASSERT_EQ(test, ret, 0); =20 --=20 2.43.0 No virus found Checked by Hillstone Network AntiVirus