[PATCH] RDMA/core: fix memory alloc/free for pfn_list

Akhilesh Patil posted 1 patch 1 month, 3 weeks ago
drivers/infiniband/core/umem_odp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] RDMA/core: fix memory alloc/free for pfn_list
Posted by Akhilesh Patil 1 month, 3 weeks ago
Ensure memory allocated for umem_odp->map->pfn_list using kvcalloc()
is freed using corresponding kvfree() to avoid potential memory
corruption. Match memory allocation and free routines kvcalloc -> kvfree

Fixes: 259e9bd07c57 ("RDMA/core: Avoid hmm_dma_map_alloc() for virtual DMA devices")
Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
---
 drivers/infiniband/core/umem_odp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c
index b1c44ec1a3f3..572a91a62a7b 100644
--- a/drivers/infiniband/core/umem_odp.c
+++ b/drivers/infiniband/core/umem_odp.c
@@ -115,7 +115,7 @@ static int ib_init_umem_odp(struct ib_umem_odp *umem_odp,
 
 out_free_map:
 	if (ib_uses_virt_dma(dev))
-		kfree(map->pfn_list);
+		kvfree(map->pfn_list);
 	else
 		hmm_dma_map_free(dev->dma_device, map);
 	return ret;
@@ -287,7 +287,7 @@ static void ib_umem_odp_free(struct ib_umem_odp *umem_odp)
 	mutex_unlock(&umem_odp->umem_mutex);
 	mmu_interval_notifier_remove(&umem_odp->notifier);
 	if (ib_uses_virt_dma(dev))
-		kfree(umem_odp->map.pfn_list);
+		kvfree(umem_odp->map.pfn_list);
 	else
 		hmm_dma_map_free(dev->dma_device, &umem_odp->map);
 }
-- 
2.34.1
Re: [PATCH] RDMA/core: fix memory alloc/free for pfn_list
Posted by Leon Romanovsky 1 month, 3 weeks ago
On Sun, 10 Aug 2025 23:21:58 +0530, Akhilesh Patil wrote:
> Ensure memory allocated for umem_odp->map->pfn_list using kvcalloc()
> is freed using corresponding kvfree() to avoid potential memory
> corruption. Match memory allocation and free routines kvcalloc -> kvfree
> 
> 

Applied, thanks!

[1/1] RDMA/core: fix memory alloc/free for pfn_list
      https://git.kernel.org/rdma/rdma/c/111aea0464c20f

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>