Currently the priority is only clamped against the first scheduler in the provided list at drm_sched_entity_init() time. Now that we are ensuring all schedulers have been initialized lets expand the clamp against all and by doing so make this check more robust.
Signed-off-by: Tvrtko Ursulin <[email protected]> Cc: Christian König <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Philipp Stanner <[email protected]> --- drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 69bcefdf2c55..ac15247f462a 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -132,6 +132,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, unsigned int num_sched_list, atomic_t *guilty) { + unsigned int i; + if (!entity || !sched_list || !num_sched_list) return -EINVAL; @@ -151,17 +153,20 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->sched_list = num_sched_list > 1 ? sched_list : NULL; RB_CLEAR_NODE(&entity->rb_tree_node); - if (priority >= sched_list[0]->num_user_rqs) { + for (i = 0; i < num_sched_list; i++) { + if (priority < sched_list[i]->num_user_rqs) + continue; + /* * The "priority" of an entity cannot exceed the number of * run-queues of a scheduler. Protect against num_rqs being 0, * by converting to signed. Choose the lowest priority * available. */ - dev_err(sched_list[0]->dev, "entity with out-of-bounds priority:%u num_user_rqs:%u\n", - priority, sched_list[0]->num_user_rqs); + dev_err(sched_list[i]->dev, "entity with out-of-bounds priority:%u num_user_rqs:%u\n", + priority, sched_list[i]->num_user_rqs); priority = max_t(s32, - (s32)sched_list[0]->num_user_rqs - 1, + (s32)sched_list[i]->num_user_rqs - 1, (s32)DRM_SCHED_PRIORITY_KERNEL); } -- 2.56.0
