drm/amdkfd: Fix memory leak in kfd_mem_dmamap_userptr()
authorRafael Mendonca <rafaelmendsr@gmail.com>
Tue, 18 Oct 2022 01:27:50 +0000 (22:27 -0300)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 24 Oct 2022 18:34:27 +0000 (14:34 -0400)
commit7b5a4d7b9e2952a15c8d2b2391dfacd7ce841a1a
treede593280b53e96e93f382781fea5397093abf6ea
parent20293269d81779a0d0c0865f5877b240c3335c97
drm/amdkfd: Fix memory leak in kfd_mem_dmamap_userptr()

If the number of pages from the userptr BO differs from the SG BO then the
allocated memory for the SG table doesn't get freed before returning
-EINVAL, which may lead to a memory leak in some error paths. Fix this by
checking the number of pages before allocating memory for the SG table.

Fixes: 264fb4d332f5 ("drm/amdgpu: Add multi-GPU DMA mapping helpers")
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c