[PATCH v2 08/11] media: intel/ipu6: return an error from ipu6_dma_map_sg() on failure

From: Valerii Sokolov

Date: Tue Nov 03 2026 - 16:19:24 EST


ipu6_dma_map_sg() returns negative error codes (-EFAULT, -ENOMEM) on its
early failure paths, and ipu6_dma_map_sgtable() only treats negative
return values as errors. However, when ipu6_mmu_map() fails in the loop,
ipu6_dma_map_sg() returns 0 instead of the negative error code from
ipu6_mmu_map(). As a result, ipu6_dma_map_sgtable() sets sgt->nents to 0
and returns success, and callers such as ipu6_isys_buf_init() and
ipu6_map_fw_region() go on to hand the hardware an address that is not
mapped in the IPU MMU.

Return the negative error code from ipu6_mmu_map() when mapping fails in
ipu6_dma_map_sg().

Fixes: daabc5c64703 ("media: ipu6: not override the dma_ops of device in driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Valerii Sokolov <valerii.sokolov@xxxxx>
---
Changes in v2:
- Return the negative error code from ipu6_dma_map_sg() instead of
checking for 0 in ipu6_dma_map_sgtable() (Sakari Ailus).

drivers/media/pci/intel/ipu6/ipu6-dma.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c b/drivers/media/pci/intel/ipu6/ipu6-dma.c
index a923a1e4bd..91c3c97838 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-dma.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -392,7 +392,7 @@ int ipu6_dma_map_sg(struct ipu6_bus_device *sys, struct scatterlist *sglist,
struct iova *iova;
size_t npages = 0;
unsigned long iova_addr;
- int i;
+ int i, ret;

for_each_sg(sglist, sg, nents, i) {
if (sg->offset) {
@@ -422,7 +422,6 @@ int ipu6_dma_map_sg(struct ipu6_bus_device *sys, struct scatterlist *sglist,
iova_addr = iova->pfn_lo;
for_each_sg(sglist, sg, nents, i) {
phys_addr_t iova_pa;
- int ret;

iova_pa = PFN_PHYS(iova_addr);
dev_dbg(dev, "mapping entry %d: iova %pap phy %pap size %d\n",
@@ -449,7 +448,7 @@ int ipu6_dma_map_sg(struct ipu6_bus_device *sys, struct scatterlist *sglist,
else
__free_iova(&mmu->dmap->iovad, iova);

- return 0;
+ return ret;
}
EXPORT_SYMBOL_NS_GPL(ipu6_dma_map_sg, "INTEL_IPU6");

--
2.56.0