Skip to content

Commit 494f2e4

Browse files
PhilipYangAalexdeucher
authored andcommitted
drm/amdkfd: fix double free mem structure
drm_gem_object_put calls release_notify callback to free the mem structure and unreserve_mem_limit, move it down after the last access of mem and make it conditional call. Signed-off-by: Philip Yang <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent fc2c456 commit 494f2e4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
13961396
struct sg_table *sg = NULL;
13971397
uint64_t user_addr = 0;
13981398
struct amdgpu_bo *bo;
1399-
struct drm_gem_object *gobj;
1399+
struct drm_gem_object *gobj = NULL;
14001400
u32 domain, alloc_domain;
14011401
u64 alloc_flags;
14021402
int ret;
@@ -1506,14 +1506,16 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
15061506
remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info);
15071507
drm_vma_node_revoke(&gobj->vma_node, drm_priv);
15081508
err_node_allow:
1509-
drm_gem_object_put(gobj);
15101509
/* Don't unreserve system mem limit twice */
15111510
goto err_reserve_limit;
15121511
err_bo_create:
15131512
unreserve_mem_limit(adev, size, alloc_domain, !!sg);
15141513
err_reserve_limit:
15151514
mutex_destroy(&(*mem)->lock);
1516-
kfree(*mem);
1515+
if (gobj)
1516+
drm_gem_object_put(gobj);
1517+
else
1518+
kfree(*mem);
15171519
err:
15181520
if (sg) {
15191521
sg_free_table(sg);

0 commit comments

Comments
 (0)