Re: [PATCH v2 1/2] dma: call unconditionally to unmap_page and unmap_sg callbacks

From: Leon Romanovsky
Date: Thu Jul 18 2024 - 02:34:11 EST


On Thu, Jul 18, 2024 at 05:49:10AM +0200, Christoph Hellwig wrote:
> On Wed, Jul 17, 2024 at 03:37:10PM +0300, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@xxxxxxxxxx>
> >
> > Almost all users of ->map_page()/map_sg() callbacks implement
> > ->unmap_page()/unmap_sg() callbacks too. One user which doesn't do it,
> > is dummy DMA ops interface, and the use of this interface is to fail
> > the operation and in such case, there won't be any call to
> > ->unmap_page()/unmap_sg().
> >
> > This patch removes the existence checks of ->unmap_page()/unmap_sg()
> > and calls to it directly to create symmetrical interface to
> > ->map_page()/map_sg().
>
> I don't think you even need this any more, do you?

Strictly saying, I don't need it, but it is still worth to have this
patch. It removes unnecessary "if" check and makes sure that all callers
of map_XXX() will provide unmap_XXX() too.

Without this patch, the code will look like:

313 else if (dma_is_default_iommu(dev))
314 iommu_dma_unmap_sg(dev, sg, nents, dir, attrs);
315 else if (ops->unmap_sg)
316 ops->unmap_sg(dev, sg, nents, dir, attrs);

With this patch:

313 else if (dma_is_default_iommu(dev))
314 iommu_dma_unmap_sg(dev, sg, nents, dir, attrs);
315 else
316 ops->unmap_sg(dev, sg, nents, dir, attrs);

Thanks