drm/ast: Fix memleak in error path in ast_bo_create()
authorEgbert Eich <eich@suse.de>
Tue, 18 Jul 2017 14:47:38 +0000 (16:47 +0200)
committerDave Airlie <airlied@redhat.com>
Wed, 2 Aug 2017 02:12:31 +0000 (12:12 +1000)
The allocated struct ast_bo was not freed in all error paths.
This patch consolidates error handling and fixes this.

Signed-off-by: Egbert Eich <eich@suse.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/ast/ast_ttm.c

index 0b4c574defe72692837ccecbc4ca97a9d5ccac66..696a15dc2f3f9965e775ea3579383502edff4b57 100644 (file)
@@ -323,10 +323,8 @@ int ast_bo_create(struct drm_device *dev, int size, int align,
                return -ENOMEM;
 
        ret = drm_gem_object_init(dev, &astbo->gem, size);
-       if (ret) {
-               kfree(astbo);
-               return ret;
-       }
+       if (ret)
+               goto error;
 
        astbo->bo.bdev = &ast->ttm.bdev;
 
@@ -340,10 +338,13 @@ int ast_bo_create(struct drm_device *dev, int size, int align,
                          align >> PAGE_SHIFT, false, NULL, acc_size,
                          NULL, NULL, ast_bo_ttm_destroy);
        if (ret)
-               return ret;
+               goto error;
 
        *pastbo = astbo;
        return 0;
+error:
+       kfree(astbo);
+       return ret;
 }
 
 static inline u64 ast_bo_gpu_offset(struct ast_bo *bo)