Skip to contentSkip to conversation

drm/amdgpu: clear job on failure in amdgpu_job_alloc(_with_ib)

PATCH In review Pierre-Eric Pelloux-Prayer 3 participants 4 messages Nov 24, 2025

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

PATCH 1/2 drm/amdgpu: clear job on failure in amdgpu_job_alloc(_with_ib)

If memory is freed we need to nullify the pointer or the caller might call kfree again (eg: amdgpu_cs_parser_fini calls kfree on all non-null job pointers).

Fixes a35c520c1611 ("drm/amdgpu: clean up and unify hw fence handling")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -0
index efa3281145f6..2fc3d9da0fe7 100644
@@ -225,6 +225,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	kfree((*job)->hw_fence);
 err_job:
 	kfree(*job);
+	*job = NULL;
 
 	return r;
 }
@@ -246,6 +247,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
 		if (entity)
 			drm_sched_job_cleanup(&(*job)->base);
 		kfree(*job);
+		*job = NULL;
 	}
 
 	return r;
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 drm/amdgpu: free job fences on failure in amdgpu_job_alloc_with_ib

Otherwise we're leaking memory.

Fixes a35c520c1611 ("drm/amdgpu: clean up and unify hw fence handling")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -0
index 2fc3d9da0fe7..91f1232b7d41 100644
@@ -246,6 +246,8 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
 	if (r) {
 		if (entity)
 			drm_sched_job_cleanup(&(*job)->base);
+		kfree((*job)->hw_vm_fence);
+		kfree((*job)->hw_fence);
 		kfree(*job);
 		*job = NULL;
 	}
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] drm/amdgpu: free job fences on failure in amdgpu_job_alloc_with_ib

Quoted 5 lines · Pierre-Eric Pelloux-Prayer

Otherwise we're leaking memory.

Fixes a35c520c1611 ("drm/amdgpu: clean up and unify hw fence handling")

Series is:

Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -1
index 2fc3d9da0fe7..91f1232b7d41 100644
@@ -246,6 +246,8 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
        if (r) {
                if (entity)
                        drm_sched_job_cleanup(&(*job)->base);
+               kfree((*job)->hw_vm_fence);
+               kfree((*job)->hw_fence);
                kfree(*job);
                *job = NULL;
        }
--

2.43.0

maintainer Reviewed-by on v1 1/2
#3 lore raw
In reply to Pierre-Eric Pelloux-Prayer
Quoted 6 lines · Pierre-Eric Pelloux-Prayer

If memory is freed we need to nullify the pointer or the caller might call kfree again (eg: amdgpu_cs_parser_fini calls kfree on all non-null job pointers).

Fixes a35c520c1611 ("drm/amdgpu: clean up and unify hw fence handling")
Quoted 24 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -0
index efa3281145f6..2fc3d9da0fe7 100644
@@ -225,6 +225,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	kfree((*job)->hw_fence);
 err_job:
 	kfree(*job);
+	*job = NULL;
 
 	return r;
 }
@@ -246,6 +247,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
 		if (entity)
 			drm_sched_job_cleanup(&(*job)->base);
 		kfree(*job);
+		*job = NULL;
 	}
 
 	return r;