Skip to content

Commit f7b86fa

Browse files
ChristianKoenigAMDgregkh
authored andcommitted
drm/amdgpu: fix error handling in amdgpu_cs_user_fence_chunk
[ Upstream commit 0165de9 ] 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> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f2c9d68 commit f7b86fa

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
3737
{
3838
struct drm_gem_object *gobj;
3939
unsigned long size;
40+
int r;
4041

4142
gobj = drm_gem_object_lookup(p->filp, data->handle);
4243
if (gobj == NULL)
@@ -48,20 +49,26 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
4849
p->uf_entry.tv.shared = true;
4950
p->uf_entry.user_pages = NULL;
5051

51-
size = amdgpu_bo_size(p->uf_entry.robj);
52-
if (size != PAGE_SIZE || (data->offset + 8) > size)
53-
return -EINVAL;
54-
55-
*offset = data->offset;
56-
5752
drm_gem_object_put_unlocked(gobj);
5853

54+
size = amdgpu_bo_size(p->uf_entry.robj);
55+
if (size != PAGE_SIZE || (data->offset + 8) > size) {
56+
r = -EINVAL;
57+
goto error_unref;
58+
}
59+
5960
if (amdgpu_ttm_tt_get_usermm(p->uf_entry.robj->tbo.ttm)) {
60-
amdgpu_bo_unref(&p->uf_entry.robj);
61-
return -EINVAL;
61+
r = -EINVAL;
62+
goto error_unref;
6263
}
6364

65+
*offset = data->offset;
66+
6467
return 0;
68+
69+
error_unref:
70+
amdgpu_bo_unref(&p->uf_entry.robj);
71+
return r;
6572
}
6673

6774
static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)

0 commit comments

Comments
 (0)