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 | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c 
b/drivers/gpu/drm/scheduler/sched_entity.c
index e12709b7bd0c..95bb79b3d003 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);
 
-- 
2.55.0

Reply via email to