Skip to content

Commit d9e63f1

Browse files
PhilipYangAgregkh
authored andcommitted
drm/amdkfd: fix double free mem structure
[ Upstream commit 494f2e4 ] 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 <Philip.Yang@amd.com> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 00a3f7f commit d9e63f1

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
@@ -1393,7 +1393,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
13931393
struct sg_table *sg = NULL;
13941394
uint64_t user_addr = 0;
13951395
struct amdgpu_bo *bo;
1396-
struct drm_gem_object *gobj;
1396+
struct drm_gem_object *gobj = NULL;
13971397
u32 domain, alloc_domain;
13981398
u64 alloc_flags;
13991399
int ret;
@@ -1503,14 +1503,16 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
15031503
remove_kgd_mem_from_kfd_bo_list(*mem, avm->process_info);
15041504
drm_vma_node_revoke(&gobj->vma_node, drm_priv);
15051505
err_node_allow:
1506-
drm_gem_object_put(gobj);
15071506
/* Don't unreserve system mem limit twice */
15081507
goto err_reserve_limit;
15091508
err_bo_create:
15101509
unreserve_mem_limit(adev, size, alloc_domain, !!sg);
15111510
err_reserve_limit:
15121511
mutex_destroy(&(*mem)->lock);
1513-
kfree(*mem);
1512+
if (gobj)
1513+
drm_gem_object_put(gobj);
1514+
else
1515+
kfree(*mem);
15141516
err:
15151517
if (sg) {
15161518
sg_free_table(sg);

0 commit comments

Comments
 (0)