drm/amdgpu: free hw_vm_fence when fail in amdgpu_job_alloc
Subsystems (2)
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
@@ -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
Quoted 4 lines · Jiqian Chen
If
drm_sched_job_initfails,hw_vm_fenceis not freed currently, then cause memory leak.
Quoted 30 lines
Signed-off-by Jiqian Chen <[email protected]>---
v1->v2changes:
* assign the return code ofdrm_sched_job_initand 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@@ -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
Christian König
maintainerQuoted 16 lines · Jiqian Chen
If
drm_sched_job_initfails,hw_vm_fenceis not freed currently, then cause memory leak.Signed-off-by Jiqian Chen <[email protected]>---
v1->v2changes:
* assign the return code ofdrm_sched_job_initand 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
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);