diff mbox series

drm/sched: Fix bounds limiting when given a malformed entity

Message ID 20231123122422.167832-2-ltuikov89@gmail.com (mailing list archive)
State New, archived
Headers show
Series drm/sched: Fix bounds limiting when given a malformed entity | expand

Commit Message

Luben Tuikov Nov. 23, 2023, 12:24 p.m. UTC
If we're given a malformed entity in drm_sched_entity_init()--shouldn't
happen, but we verify--with out-of-bounds priority value, we set it to an
allowed value. Fix the expression which sets this limit.

Signed-off-by: Luben Tuikov <ltuikov89@gmail.com>
Fixes: 56e449603f0ac5 ("drm/sched: Convert the GPU scheduler to variable number of run-queues")
---
 drivers/gpu/drm/scheduler/sched_entity.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)


base-commit: b3c5a7de9aeb51cb19160f3f61343ed87487abde
diff mbox series

Patch

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 4d42b1e4daa67f..20c9c561843ce1 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -84,9 +84,12 @@  int drm_sched_entity_init(struct drm_sched_entity *entity,
 		/* The "priority" of an entity cannot exceed the number
 		 * of run-queues of a scheduler.
 		 */
-		if (entity->priority >= sched_list[0]->num_rqs)
-			entity->priority = max_t(u32, sched_list[0]->num_rqs,
-						 DRM_SCHED_PRIORITY_MIN);
+		if (entity->priority >= sched_list[0]->num_rqs) {
+			drm_err(sched_list[0], "entity with out-of-bounds priority:%u num_rqs:%u\n",
+				entity->priority, sched_list[0]->num_rqs);
+			entity->priority = max_t(s32, (s32) sched_list[0]->num_rqs - 1,
+						 (s32) DRM_SCHED_PRIORITY_MIN);
+		}
 		entity->rq = sched_list[0]->sched_rq[entity->priority];
 	}