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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Nov 2022 14:59:17 +0000 (23:59 +0900)
commit304a10161696d86300ceab1cbe72b2d74b8cdd94
tree5d4713b63869fd188924cf65fef3333bd017491a
parent2fe6b24ce299805667f02405118c843b2ca684e1
drm/amdkfd: Fix memory leak in kfd_mem_dmamap_userptr()

[ Upstream commit 90bfee142af0f0e9d3bec80e7acd5f49b230acf7 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c