drm/amdgpu: handle error case for ctx
authorChunming Zhou <David1.Zhou@amd.com>
Thu, 10 Dec 2015 07:50:02 +0000 (15:50 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 15 Dec 2015 00:42:11 +0000 (19:42 -0500)
Properly handle ctx init failure.

Signed-off-by: Chunming Zhou <David1.Zhou@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c

index c1f2308b41159cb6c5d042c10f1528486c1e772d..15e341634536f202442205f93e663e08b2dae0df 100644 (file)
@@ -56,7 +56,6 @@ int amdgpu_ctx_init(struct amdgpu_device *adev, enum amd_sched_priority pri,
                        for (j = 0; j < i; j++)
                                amd_sched_entity_fini(&adev->rings[j]->sched,
                                                      &ctx->rings[j].entity);
-                       kfree(ctx);
                        return r;
                }
        }
@@ -103,8 +102,12 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
        }
        *id = (uint32_t)r;
        r = amdgpu_ctx_init(adev, AMD_SCHED_PRIORITY_NORMAL, ctx);
+       if (r) {
+               idr_remove(&mgr->ctx_handles, *id);
+               *id = 0;
+               kfree(ctx);
+       }
        mutex_unlock(&mgr->lock);
-
        return r;
 }