Skip to content

Commit

Permalink
drm/amdgpu: fix error handling in amdgpu_cs_user_fence_chunk
Browse files Browse the repository at this point in the history
Slowly leaking memory one page at a time :)

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
  • Loading branch information
Christian König authored and Alex Deucher committed Sep 11, 2018
1 parent 3a74987 commit 0165de9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
{
struct drm_gem_object *gobj;
unsigned long size;
int r;

gobj = drm_gem_object_lookup(p->filp, data->handle);
if (gobj == NULL)
Expand All @@ -50,20 +51,26 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
p->uf_entry.tv.shared = true;
p->uf_entry.user_pages = NULL;

size = amdgpu_bo_size(p->uf_entry.robj);
if (size != PAGE_SIZE || (data->offset + 8) > size)
return -EINVAL;

*offset = data->offset;

drm_gem_object_put_unlocked(gobj);

size = amdgpu_bo_size(p->uf_entry.robj);
if (size != PAGE_SIZE || (data->offset + 8) > size) {
r = -EINVAL;
goto error_unref;
}

if (amdgpu_ttm_tt_get_usermm(p->uf_entry.robj->tbo.ttm)) {
amdgpu_bo_unref(&p->uf_entry.robj);
return -EINVAL;
r = -EINVAL;
goto error_unref;
}

*offset = data->offset;

return 0;

error_unref:
amdgpu_bo_unref(&p->uf_entry.robj);
return r;
}

static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser *p,
Expand Down

0 comments on commit 0165de9

Please sign in to comment.