drm/amdgpu: Fix double free in amdgpu_userq_fence_driver_alloc()
authorDan Carpenter <dan.carpenter@linaro.org>
Sat, 12 Apr 2025 14:39:32 +0000 (17:39 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 21 Apr 2025 14:52:53 +0000 (10:52 -0400)
The goto frees "fence_drv" so this is a double free bug.  There is no
need to call amdgpu_seq64_free(adev, fence_drv->va) since the seq64
allocation failed so change the goto to goto free_fence_drv.  Also
propagate the error code from amdgpu_seq64_alloc() instead of hard coding
it to -ENOMEM.

Fixes: e7cf21fbb277 ("drm/amdgpu: Few optimization and fixes for userq fence driver")
Reviewed-by: Arvind Yadav <arvind.yadav@amd.com>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c

index ee73d7846c2cafbd9723808b7d6e6678fa1f2721..e2e0bd6ae807e9e7f171b18a99aa34dae9ccb4ed 100644 (file)
@@ -84,11 +84,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
        /* Acquire seq64 memory */
        r = amdgpu_seq64_alloc(adev, &fence_drv->va, &fence_drv->gpu_addr,
                               &fence_drv->cpu_addr);
-       if (r) {
-               kfree(fence_drv);
-               r = -ENOMEM;
-               goto free_seq64;
-       }
+       if (r)
+               goto free_fence_drv;
 
        memset(fence_drv->cpu_addr, 0, sizeof(u64));