drm/amdgpu: free hw_vm_fence when fail in amdgpu_job_alloc
Subsystems (2)
PATCH 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +3 -3
@@ -216,11 +216,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, (*job)->generation =amdgpu_vm_generation (adev, vm); (*job)->vm_pd_addr =AMDGPU_BO_INVALID_OFFSET ; -if (!entity) +if (!entity || + !drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id))return 0 ; -return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); +kfree ((*job)->hw_vm_fence); err_fence:kfree ((*job)->hw_fence);
Signature · 1 line
2.34.1
Christian König
maintainerQuoted 13 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]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 6 +++--- 1 file changed, 3 insertions(+), 3 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 221
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2
-1@@ -216,11 +216,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, (*job)->generation =amdgpu_vm_generation (adev, vm); (*job)->vm_pd_addr =AMDGPU_BO_INVALID_OFFSET ; -if (!entity) +if (!entity || + !drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id))return 0 ;
That is not even remotely correct.
You need to assign the return code and check that instead, otherwise you return success when a failure occurred and just crash.
Regards,
Christian.
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-2-return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); +kfree ((*job)->hw_vm_fence); err_fence:kfree ((*job)->hw_fence);
Quoted 19 lines · Christian König
Quoted 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]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -216,11 +216,11 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, (*job)->generation =amdgpu_vm_generation (adev, vm); (*job)->vm_pd_addr =AMDGPU_BO_INVALID_OFFSET ;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 221
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2
-1-if (!entity) +if (!entity || + !drm_sched_job_init (&(*job)->base, entity,1 , owner, drm_client_id))return 0 ;That is not even remotely correct.
You need to assign the return code and check that instead, otherwise you return success when a failure occurred and just crash.
You're right, I've realized that too.
Will change in next version.
Quoted 12 lines
Regards,
Christian.Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-2-return drm_sched_job_init (&(*job)->base, entity,1 , owner, - drm_client_id); +kfree ((*job)->hw_vm_fence); err_fence:kfree ((*job)->hw_fence);
Signature · 2 lines
Best regards, Jiqian Chen.