summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>2018-02-05 05:45:53 -0500
committerJoerg Roedel <jroedel@suse.de>2018-02-13 13:31:20 -0500
commitc5611a8751e67595e4e7d3feaff3c900b92094b9 (patch)
treeb833cce9dd9ad3501f7ba151aadf09faeaa2a6b9
parent7928b2cbe55b2a410a0f5c1f154610059c57b1b2 (diff)
iommu: Do not return error code for APIs with size_t return type
Currently, iommu_unmap, iommu_unmap_fast and iommu_map_sg return size_t. However, some of the return values are error codes (< 0), which can be misinterpreted as large size. Therefore, returning size 0 instead to signify failure to map/unmap. Cc: Joerg Roedel <joro@8bytes.org> Cc: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r--drivers/iommu/amd_iommu.c2
-rw-r--r--drivers/iommu/iommu.c6
-rw-r--r--include/linux/iommu.h14
3 files changed, 11 insertions, 11 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 74788fdeb773..ecdeb045deef 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3050,7 +3050,7 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
3050 size_t unmap_size; 3050 size_t unmap_size;
3051 3051
3052 if (domain->mode == PAGE_MODE_NONE) 3052 if (domain->mode == PAGE_MODE_NONE)
3053 return -EINVAL; 3053 return 0;
3054 3054
3055 mutex_lock(&domain->api_lock); 3055 mutex_lock(&domain->api_lock);
3056 unmap_size = iommu_unmap_page(domain, iova, page_size); 3056 unmap_size = iommu_unmap_page(domain, iova, page_size);
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 69fef991c651..d2aa23202bb9 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1573,10 +1573,10 @@ static size_t __iommu_unmap(struct iommu_domain *domain,
1573 1573
1574 if (unlikely(ops->unmap == NULL || 1574 if (unlikely(ops->unmap == NULL ||
1575 domain->pgsize_bitmap == 0UL)) 1575 domain->pgsize_bitmap == 0UL))
1576 return -ENODEV; 1576 return 0;
1577 1577
1578 if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING))) 1578 if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
1579 return -EINVAL; 1579 return 0;
1580 1580
1581 /* find out the minimum page size supported */ 1581 /* find out the minimum page size supported */
1582 min_pagesz = 1 << __ffs(domain->pgsize_bitmap); 1582 min_pagesz = 1 << __ffs(domain->pgsize_bitmap);
@@ -1589,7 +1589,7 @@ static size_t __iommu_unmap(struct iommu_domain *domain,
1589 if (!IS_ALIGNED(iova | size, min_pagesz)) { 1589 if (!IS_ALIGNED(iova | size, min_pagesz)) {
1590 pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%x\n", 1590 pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%x\n",
1591 iova, size, min_pagesz); 1591 iova, size, min_pagesz);
1592 return -EINVAL; 1592 return 0;
1593 } 1593 }
1594 1594
1595 pr_debug("unmap this: iova 0x%lx size 0x%zx\n", iova, size); 1595 pr_debug("unmap this: iova 0x%lx size 0x%zx\n", iova, size);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 41b8c5757859..19938ee6eb31 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -465,23 +465,23 @@ static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
465 return -ENODEV; 465 return -ENODEV;
466} 466}
467 467
468static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova, 468static inline size_t iommu_unmap(struct iommu_domain *domain,
469 size_t size) 469 unsigned long iova, size_t size)
470{ 470{
471 return -ENODEV; 471 return 0;
472} 472}
473 473
474static inline int iommu_unmap_fast(struct iommu_domain *domain, unsigned long iova, 474static inline size_t iommu_unmap_fast(struct iommu_domain *domain,
475 int gfp_order) 475 unsigned long iova, int gfp_order)
476{ 476{
477 return -ENODEV; 477 return 0;
478} 478}
479 479
480static inline size_t iommu_map_sg(struct iommu_domain *domain, 480static inline size_t iommu_map_sg(struct iommu_domain *domain,
481 unsigned long iova, struct scatterlist *sg, 481 unsigned long iova, struct scatterlist *sg,
482 unsigned int nents, int prot) 482 unsigned int nents, int prot)
483{ 483{
484 return -ENODEV; 484 return 0;
485} 485}
486 486
487static inline void iommu_flush_tlb_all(struct iommu_domain *domain) 487static inline void iommu_flush_tlb_all(struct iommu_domain *domain)