Skip to contentSkip to conversation

drm/amdgpu: free hw_vm_fence when fail in amdgpu_job_alloc

PATCH Superseded Jiqian Chen 3 participants 3 messages Jan 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdgpu: free hw_vm_fence when fail in amdgpu_job_alloc

If drm_sched_job_init fails, hw_vm_fence is not freed currently, then cause memory leak.

---
v1->v2 changes:
* assign the return code of drm_sched_job_init and check that instead.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +6 -2
index 7f5d01164897..72e1bfd3fe4c 100644
@@ -219,8 +219,12 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (!entity)
 		return 0;
 
-	return drm_sched_job_init(&(*job)->base, entity, 1, owner,
-				  drm_client_id);
+	r = drm_sched_job_init(&(*job)->base, entity, 1, owner, drm_client_id);
+	if (!r) {
+		return 0;
+	}
+
+	kfree((*job)->hw_vm_fence);
 
 err_fence:
 	kfree((*job)->hw_fence);
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Jiqian Chen

If drm_sched_job_init fails, hw_vm_fence is not freed currently, then cause memory leak.

Fixes db36632ea51e ("drm/amdgpu: clean up and unify hw fence handling")
Quoted 30 lines

---
v1->v2 changes:
* assign the return code of drm_sched_job_init and check that instead.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +6 -3
index 7f5d01164897..72e1bfd3fe4c 100644
@@ -219,8 +219,12 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
        if (!entity)
                return 0;
 
-       return drm_sched_job_init(&(*job)->base, entity, 1, owner,
-                                 drm_client_id);
+       r = drm_sched_job_init(&(*job)->base, entity, 1, owner, drm_client_id);
+       if (!r) {
+               return 0;
+       }
+
+       kfree((*job)->hw_vm_fence);
 
 err_fence:
        kfree((*job)->hw_fence);
--

2.34.1

maintainer
#2 lore raw
In reply to Jiqian Chen
Quoted 16 lines · Jiqian Chen

If drm_sched_job_init fails, hw_vm_fence is not freed currently, then cause memory leak.

---
v1->v2 changes:
* assign the return code of drm_sched_job_init and check that instead.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index 7f5d01164897..72e1bfd3fe4c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 225

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -2
@@ -219,8 +219,12 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (!entity)
 		return 0;
 
-	return drm_sched_job_init(&(*job)->base, entity, 1, owner,
-				  drm_client_id);
+	r = drm_sched_job_init(&(*job)->base, entity, 1, owner, drm_client_id);
+	if (!r) {
+		return 0;
+	}

Please drop the extra {}, and use checkpatch.pl. That tool should complain about stuff like that.

Apart from that looks good to me,
Christian.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -0
+
+	kfree((*job)->hw_vm_fence);
 
 err_fence:
 	kfree((*job)->hw_fence);