drm/amdkfd: Fix leak in dmabuf import
authorFelix Kuehling <Felix.Kuehling@amd.com>
Tue, 8 Dec 2020 17:23:15 +0000 (12:23 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 Dec 2020 10:51:30 +0000 (11:51 +0100)
[ Upstream commit c897934da15f182ce99536007f8ef61c4748c07e ]

Release dmabuf reference before returning from kfd_ioctl_import_dmabuf.
amdgpu_amdkfd_gpuvm_import_dmabuf takes a reference to the underlying
GEM BO and doesn't keep the reference to the dmabuf wrapper.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Kent Russell <kent.russell@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

index 1d3cd5c50d5f2b06191e5bf8ff1fee7bed7a6225..4a0ef9268918c60c2b39fb3c817ef3b8c0f0ec5d 100644 (file)
@@ -1664,6 +1664,7 @@ static int kfd_ioctl_import_dmabuf(struct file *filep,
        }
 
        mutex_unlock(&p->mutex);
+       dma_buf_put(dmabuf);
 
        args->handle = MAKE_HANDLE(args->gpu_id, idr_handle);
 
@@ -1673,6 +1674,7 @@ static int kfd_ioctl_import_dmabuf(struct file *filep,
        amdgpu_amdkfd_gpuvm_free_memory_of_gpu(dev->kgd, (struct kgd_mem *)mem);
 err_unlock:
        mutex_unlock(&p->mutex);
+       dma_buf_put(dmabuf);
        return r;
 }