Re: [PATCH v2 07/11] media: intel/ipu6: fix IOVA leak on first entry failure in ipu6_dma_map_sg()
From: Sakari Ailus
Date: Wed Nov 18 2026 - 04:06:06 EST
Hi Valerii,
On Wed, Nov 18, 2026 at 12:44:42AM +0000, Valerii Sokolov wrote:
> Hi Sakari,
>
> On Wed, Nov 04, 2026 at 03:02:56PM +0200, Sakari Ailus wrote:
> > On Tue, Nov 03, 2026 at 09:11:03PM +0000, Valerii Sokolov wrote:
> > > 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);
> >
> > This should be handled in ipu6_dma_unmap_sg(). I'd release the iova in the
> > beginning and reverse the order of the nents / iova checks.
> >
> > I'll merge the rest now.
>
> Sorry for the delayed reply, and thank you for merging the other
> patches!
>
> Regarding handling nents == 0 inside ipu6_dma_unmap_sg():
> ipu6_dma_unmap_sg() looks up the IOVA via:
>
> struct iova *iova = find_iova(&mmu->dmap->iovad,
> PHYS_PFN(sg_dma_address(sglist)));
>
> However, in ipu6_dma_map_sg(), sg_dma_address(sg) is only overwritten
> with PFN_PHYS(iova_addr) after ipu6_mmu_map() succeeds:
Right, then indeed this seems to be the least bad of the options. I'll pick
it.
--
Regards,
Sakari Ailus