Simplify the code and theoretical runtime combinations by disallowing initializing entities with un-initialized schedulers.
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]> --- I do not *think* any of the drivers relies on this inverted initialization order but it needs more eyes for sure. --- drivers/gpu/drm/scheduler/sched_entity.c | 30 +++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 03e68b4102d5..2844049d4c66 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -119,9 +119,16 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, unsigned int num_sched_list, atomic_t *guilty) { - if (!entity || !sched_list || !num_sched_list || !sched_list[0]) + unsigned int i; + + if (!entity || !sched_list || !num_sched_list) return -EINVAL; + for (i = 0; i < num_sched_list; i++) { + if (!sched_list[i] || !sched_list[i]->sched_rq) + return -EINVAL; + } + memset(entity, 0, sizeof(struct drm_sched_entity)); entity->stats = drm_sched_entity_stats_new(); @@ -135,13 +142,7 @@ 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 (!sched_list[0]->sched_rq) { - /* Since every entry covered by num_sched_list - * should be non-NULL and therefore we warn drivers - * not to do this and to fix their DRM calling order. - */ - pr_warn("%s: called with uninitialized scheduler\n", __func__); - } else if (priority >= sched_list[0]->num_user_rqs) { + if (priority >= sched_list[0]->num_user_rqs) { /* * The "priority" of an entity cannot exceed the number of * run-queues of a scheduler. Protect against num_rqs being 0, @@ -158,8 +159,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->priority = priority; entity->rq_priority = drm_sched_policy == DRM_SCHED_POLICY_FAIR ? DRM_SCHED_PRIORITY_KERNEL : priority; - if (sched_list[0]->sched_rq) - entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; + entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; init_completion(&entity->entity_idle); @@ -192,7 +192,15 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list) { - WARN_ON(!num_sched_list || !sched_list); + unsigned int i; + + if (WARN_ON(!num_sched_list || !sched_list)) + return; + + for (i = 0; i < num_sched_list; i++) { + if (WARN_ON(!sched_list[i] || !sched_list[i]->sched_rq)) + return; + } spin_lock(&entity->lock); entity->sched_list = sched_list; -- 2.56.0
