Skip to content

Commit cad34be

Browse files
author
Christoph Hellwig
committed
iommu/dma-iommu: remove the mapping_error dma_map_ops method
Return DMA_MAPPING_ERROR instead of 0 on a dma mapping failure and let the core dma-mapping code handle the rest. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 524a669 commit cad34be

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

arch/arm64/mm/dma-mapping.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
233233
return NULL;
234234

235235
*handle = iommu_dma_map_page(dev, page, 0, iosize, ioprot);
236-
if (iommu_dma_mapping_error(dev, *handle)) {
236+
if (*handle == DMA_MAPPING_ERROR) {
237237
if (coherent)
238238
__free_pages(page, get_order(size));
239239
else
@@ -250,7 +250,7 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
250250
return NULL;
251251

252252
*handle = iommu_dma_map_page(dev, page, 0, iosize, ioprot);
253-
if (iommu_dma_mapping_error(dev, *handle)) {
253+
if (*handle == DMA_MAPPING_ERROR) {
254254
dma_release_from_contiguous(dev, page,
255255
size >> PAGE_SHIFT);
256256
return NULL;
@@ -410,7 +410,7 @@ static dma_addr_t __iommu_map_page(struct device *dev, struct page *page,
410410
dma_addr_t dev_addr = iommu_dma_map_page(dev, page, offset, size, prot);
411411

412412
if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
413-
!iommu_dma_mapping_error(dev, dev_addr))
413+
dev_addr != DMA_MAPPING_ERROR)
414414
__dma_map_area(page_address(page) + offset, size, dir);
415415

416416
return dev_addr;
@@ -493,7 +493,6 @@ static const struct dma_map_ops iommu_dma_ops = {
493493
.sync_sg_for_device = __iommu_sync_sg_for_device,
494494
.map_resource = iommu_dma_map_resource,
495495
.unmap_resource = iommu_dma_unmap_resource,
496-
.mapping_error = iommu_dma_mapping_error,
497496
};
498497

499498
static int __init __iommu_dma_init(void)

drivers/iommu/dma-iommu.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#include <linux/scatterlist.h>
3333
#include <linux/vmalloc.h>
3434

35-
#define IOMMU_MAPPING_ERROR 0
36-
3735
struct iommu_dma_msi_page {
3836
struct list_head list;
3937
dma_addr_t iova;
@@ -523,7 +521,7 @@ void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
523521
{
524522
__iommu_dma_unmap(iommu_get_dma_domain(dev), *handle, size);
525523
__iommu_dma_free_pages(pages, PAGE_ALIGN(size) >> PAGE_SHIFT);
526-
*handle = IOMMU_MAPPING_ERROR;
524+
*handle = DMA_MAPPING_ERROR;
527525
}
528526

529527
/**
@@ -556,7 +554,7 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
556554
dma_addr_t iova;
557555
unsigned int count, min_size, alloc_sizes = domain->pgsize_bitmap;
558556

559-
*handle = IOMMU_MAPPING_ERROR;
557+
*handle = DMA_MAPPING_ERROR;
560558

561559
min_size = alloc_sizes & -alloc_sizes;
562560
if (min_size < PAGE_SIZE) {
@@ -649,11 +647,11 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
649647

650648
iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev);
651649
if (!iova)
652-
return IOMMU_MAPPING_ERROR;
650+
return DMA_MAPPING_ERROR;
653651

654652
if (iommu_map(domain, iova, phys - iova_off, size, prot)) {
655653
iommu_dma_free_iova(cookie, iova, size);
656-
return IOMMU_MAPPING_ERROR;
654+
return DMA_MAPPING_ERROR;
657655
}
658656
return iova + iova_off;
659657
}
@@ -694,7 +692,7 @@ static int __finalise_sg(struct device *dev, struct scatterlist *sg, int nents,
694692

695693
s->offset += s_iova_off;
696694
s->length = s_length;
697-
sg_dma_address(s) = IOMMU_MAPPING_ERROR;
695+
sg_dma_address(s) = DMA_MAPPING_ERROR;
698696
sg_dma_len(s) = 0;
699697

700698
/*
@@ -737,11 +735,11 @@ static void __invalidate_sg(struct scatterlist *sg, int nents)
737735
int i;
738736

739737
for_each_sg(sg, s, nents, i) {
740-
if (sg_dma_address(s) != IOMMU_MAPPING_ERROR)
738+
if (sg_dma_address(s) != DMA_MAPPING_ERROR)
741739
s->offset += sg_dma_address(s);
742740
if (sg_dma_len(s))
743741
s->length = sg_dma_len(s);
744-
sg_dma_address(s) = IOMMU_MAPPING_ERROR;
742+
sg_dma_address(s) = DMA_MAPPING_ERROR;
745743
sg_dma_len(s) = 0;
746744
}
747745
}
@@ -858,11 +856,6 @@ void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
858856
__iommu_dma_unmap(iommu_get_dma_domain(dev), handle, size);
859857
}
860858

861-
int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
862-
{
863-
return dma_addr == IOMMU_MAPPING_ERROR;
864-
}
865-
866859
static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,
867860
phys_addr_t msi_addr, struct iommu_domain *domain)
868861
{
@@ -882,7 +875,7 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,
882875
return NULL;
883876

884877
iova = __iommu_dma_map(dev, msi_addr, size, prot, domain);
885-
if (iommu_dma_mapping_error(dev, iova))
878+
if (iova == DMA_MAPPING_ERROR)
886879
goto out_free_page;
887880

888881
INIT_LIST_HEAD(&msi_page->list);

include/linux/dma-iommu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
6969
size_t size, enum dma_data_direction dir, unsigned long attrs);
7070
void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
7171
size_t size, enum dma_data_direction dir, unsigned long attrs);
72-
int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
7372

7473
/* The DMA API isn't _quite_ the whole story, though... */
7574
void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);

0 commit comments

Comments
 (0)