[Mesa-dev] [PATCH 06/18] winsys/amdgpu: cleanup error handling in amdgpu_ctx_create

Nicolai Hähnle nhaehnle at gmail.com
Mon May 9 23:21:24 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/winsys/amdgpu/drm/amdgpu_cs.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
index 0bd776d..acae6cd 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
@@ -145,14 +145,16 @@ static struct radeon_winsys_ctx *amdgpu_ctx_create(struct radeon_winsys *ws)
    struct amdgpu_bo_alloc_request alloc_buffer = {};
    amdgpu_bo_handle buf_handle;
 
+   if (!ctx)
+      return NULL;
+
    ctx->ws = amdgpu_winsys(ws);
    ctx->refcount = 1;
 
    r = amdgpu_cs_ctx_create(ctx->ws->dev, &ctx->ctx);
    if (r) {
       fprintf(stderr, "amdgpu: amdgpu_cs_ctx_create failed. (%i)\n", r);
-      FREE(ctx);
-      return NULL;
+      goto error_create;
    }
 
    alloc_buffer.alloc_size = 4 * 1024;
@@ -162,24 +164,27 @@ static struct radeon_winsys_ctx *amdgpu_ctx_create(struct radeon_winsys *ws)
    r = amdgpu_bo_alloc(ctx->ws->dev, &alloc_buffer, &buf_handle);
    if (r) {
       fprintf(stderr, "amdgpu: amdgpu_bo_alloc failed. (%i)\n", r);
-      amdgpu_cs_ctx_free(ctx->ctx);
-      FREE(ctx);
-      return NULL;
+      goto error_user_fence_alloc;
    }
 
    r = amdgpu_bo_cpu_map(buf_handle, (void**)&ctx->user_fence_cpu_address_base);
    if (r) {
       fprintf(stderr, "amdgpu: amdgpu_bo_cpu_map failed. (%i)\n", r);
-      amdgpu_bo_free(buf_handle);
-      amdgpu_cs_ctx_free(ctx->ctx);
-      FREE(ctx);
-      return NULL;
+      goto error_user_fence_map;
    }
 
    memset(ctx->user_fence_cpu_address_base, 0, alloc_buffer.alloc_size);
    ctx->user_fence_bo = buf_handle;
 
    return (struct radeon_winsys_ctx*)ctx;
+
+error_user_fence_map:
+   amdgpu_bo_free(buf_handle);
+error_user_fence_alloc:
+   amdgpu_cs_ctx_free(ctx->ctx);
+error_create:
+   FREE(ctx);
+   return NULL;
 }
 
 static void amdgpu_ctx_destroy(struct radeon_winsys_ctx *rwctx)
-- 
2.7.4



More information about the mesa-dev mailing list