Skip to content

Commit

Permalink
drm/amdgpu: fix memory leak
Browse files Browse the repository at this point in the history
cleanup error handling code and make sure temporary info array
with the handles are freed by amdgpu_bo_list_put() on
idr_replace()'s failure.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
  • Loading branch information
Nirmoy Das authored and Alex Deucher committed Oct 9, 2019
1 parent da0c9ea commit 083164d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,

r = amdgpu_bo_create_list_entry_array(&args->in, &info);
if (r)
goto error_free;
return r;

switch (args->in.operation) {
case AMDGPU_BO_LIST_OP_CREATE:
Expand All @@ -283,8 +283,7 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
mutex_unlock(&fpriv->bo_list_lock);
if (r < 0) {
amdgpu_bo_list_put(list);
return r;
goto error_put_list;
}

handle = r;
Expand All @@ -306,9 +305,8 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
mutex_unlock(&fpriv->bo_list_lock);

if (IS_ERR(old)) {
amdgpu_bo_list_put(list);
r = PTR_ERR(old);
goto error_free;
goto error_put_list;
}

amdgpu_bo_list_put(old);
Expand All @@ -325,8 +323,10 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,

return 0;

error_put_list:
amdgpu_bo_list_put(list);

error_free:
if (info)
kvfree(info);
kvfree(info);
return r;
}

0 comments on commit 083164d

Please sign in to comment.