drm_sched_job_add_resv_dependencies can fail in amdgpu_ttm_prepare_job.
In this case we need to use amdgpu_job_free to release memory.

---
v4: moved job pointer clearing to a different patchset
---

Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index ae3ad19667df..6e8b6fd94378 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2278,7 +2278,7 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, 
uint64_t src_offset,
                                   resv, vm_needs_flush, &job, false,
                                   AMDGPU_KERNEL_JOB_ID_TTM_COPY_BUFFER);
        if (r)
-               return r;
+               goto error_free;
 
        for (i = 0; i < num_loops; i++) {
                uint32_t cur_size_in_bytes = min(byte_count, max_bytes);
@@ -2290,11 +2290,9 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, 
uint64_t src_offset,
                byte_count -= cur_size_in_bytes;
        }
 
-       if (r)
-               goto error_free;
        *fence = amdgpu_ttm_job_submit(adev, job, num_dw);
 
-       return r;
+       return 0;
 
 error_free:
        amdgpu_job_free(job);
-- 
2.43.0

Reply via email to