[PATCH v1 07/11] media: intel/ipu6: fix IOVA leak on first entry failure in ipu6_dma_map_sg()

From: Valerii Sokolov

Date: Fri Oct 23 2026 - 16:13:47 EST


If ipu6_mmu_map() fails for the first scatterlist entry,
ipu6_dma_map_sg() calls ipu6_dma_unmap_sg() with nents == 0. That
returns immediately, so the IOVA range allocated with alloc_iova() is
never freed.

Free the IOVA directly when no entry has been mapped yet.

Fixes: 9163d83573e4 ("media: intel/ipu6: add IPU6 DMA mapping API and MMU table")
Signed-off-by: Valerii Sokolov <valerii.sokolov@xxxxx>
---
drivers/media/pci/intel/ipu6/ipu6-dma.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c b/drivers/media/pci/intel/ipu6/ipu6-dma.c
index 90f530a937..a923a1e4bd 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-dma.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -444,7 +444,10 @@ int ipu6_dma_map_sg(struct ipu6_bus_device *sys, struct scatterlist *sglist,
return nents;

out_fail:
- ipu6_dma_unmap_sg(sys, sglist, i, dir, attrs);
+ if (i)
+ ipu6_dma_unmap_sg(sys, sglist, i, dir, attrs);
+ else
+ __free_iova(&mmu->dmap->iovad, iova);

return 0;
}
--
2.56.0