Check drm_sched_entity_init() return value since ever since commit
fd177135f0e6 ("drm/sched: Account entity GPU time")
drm_sched_entity_init() can fail with -ENOMEM regardless of the sanity of
the input parameters.

Signed-off-by: Tvrtko Ursulin <[email protected]>
Fixes: fd177135f0e6 ("drm/sched: Account entity GPU time")
Cc: Lucas Stach <[email protected]>
Cc: Russell King <[email protected]>
Cc: Christian Gmeiner <[email protected]>
Cc: [email protected]
Cc: <[email protected]> # v7.2+
---
Compile tested only.
---
 drivers/gpu/drm/etnaviv/etnaviv_drv.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c 
b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
index 7bd7aef723c3..53003c31d7f9 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
@@ -83,21 +83,29 @@ static int etnaviv_open(struct drm_device *dev, struct 
drm_file *file)
        }
 
        for (i = 0; i < ETNA_MAX_PIPES; i++) {
-               struct etnaviv_gpu *gpu = priv->gpu[i];
                struct drm_gpu_scheduler *sched;
 
-               if (gpu) {
-                       sched = &gpu->sched;
-                       drm_sched_entity_init(&ctx->sched_entity[i],
-                                             DRM_SCHED_PRIORITY_NORMAL, &sched,
-                                             1, NULL);
-               }
+               if (!priv->gpu[i])
+                       continue;
+
+               sched = &priv->gpu[i]->sched;
+               ret = drm_sched_entity_init(&ctx->sched_entity[i],
+                                           DRM_SCHED_PRIORITY_NORMAL,
+                                           &sched, 1, NULL);
+               if (ret)
+                       goto out_entity;
        }
 
        file->driver_priv = ctx;
 
        return 0;
 
+out_entity:
+       while (i--) {
+               if (priv->gpu[i])
+                       drm_sched_entity_destroy(&ctx->sched_entity[i]);
+       }
+       etnaviv_iommu_context_put(ctx->mmu);
 out_id:
        xa_erase(&priv->active_contexts, ctx->id);
 out_free:
-- 
2.56.0

Reply via email to