Skip to content

Commit a5fb217

Browse files
author
Christoph Hellwig
committed
dma-mapping: reflow dma_supported
dma_supported has become too much spaghetti for my taste. Reflow it to remove the duplicate use_dma_iommu condition and make the main path more obvious. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]>
1 parent f45cfab commit a5fb217

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

kernel/dma/mapping.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -841,20 +841,23 @@ static int dma_supported(struct device *dev, u64 mask)
841841
{
842842
const struct dma_map_ops *ops = get_dma_ops(dev);
843843

844-
if (WARN_ON(ops && use_dma_iommu(dev)))
845-
return false;
846-
847-
if (use_dma_iommu(dev))
844+
if (use_dma_iommu(dev)) {
845+
if (WARN_ON(ops))
846+
return false;
848847
return true;
848+
}
849+
849850
/*
850-
* ->dma_supported sets the bypass flag, so we must always call
851-
* into the method here unless the device is truly direct mapped.
851+
* ->dma_supported sets and clears the bypass flag, so ignore it here
852+
* and always call into the method if there is one.
852853
*/
853-
if (!ops)
854-
return dma_direct_supported(dev, mask);
855-
if (!ops->dma_supported)
856-
return 1;
857-
return ops->dma_supported(dev, mask);
854+
if (ops) {
855+
if (!ops->dma_supported)
856+
return true;
857+
return ops->dma_supported(dev, mask);
858+
}
859+
860+
return dma_direct_supported(dev, mask);
858861
}
859862

860863
bool dma_pci_p2pdma_supported(struct device *dev)

0 commit comments

Comments
 (0)