[PATCH 1/2] iommu/dma: Add helper for coherent devs without swiotlb

From: Joe Damato

Date: Fri Nov 06 2026 - 12:58:10 EST


Factor out some repeated logic which checks if a device is coherent and
if there is a swiotlb.

Replace repeated instances of this logic with a call to the helper
instead.

Signed-off-by: Joe Damato <joe@xxxxxxx>
---
drivers/iommu/dma-iommu.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 78742aeba932..a25ee287a5ac 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -628,6 +628,12 @@ static bool dev_use_sg_swiotlb(struct device *dev, struct scatterlist *sg,
return false;
}

+static bool dev_is_coherent_no_swiotlb(struct device *dev, size_t size,
+ enum dma_data_direction dir)
+{
+ return dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir);
+}
+
/**
* iommu_dma_init_options - Initialize dma-iommu options
* @options: The options to be initialized
@@ -1103,7 +1109,7 @@ void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
{
phys_addr_t phys;

- if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir))
+ if (dev_is_coherent_no_swiotlb(dev, size, dir))
return;

phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
@@ -1120,7 +1126,7 @@ void iommu_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
{
phys_addr_t phys;

- if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev, size, dir))
+ if (dev_is_coherent_no_swiotlb(dev, size, dir))
return;

phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle);
--
2.53.0-Meta