Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5611a87 authored by Suravee Suthikulpanit's avatar Suravee Suthikulpanit Committed by Joerg Roedel
Browse files

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: default avatarSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 7928b2cb
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -3050,7 +3050,7 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
	size_t unmap_size;
	size_t unmap_size;


	if (domain->mode == PAGE_MODE_NONE)
	if (domain->mode == PAGE_MODE_NONE)
		return -EINVAL;
		return 0;


	mutex_lock(&domain->api_lock);
	mutex_lock(&domain->api_lock);
	unmap_size = iommu_unmap_page(domain, iova, page_size);
	unmap_size = iommu_unmap_page(domain, iova, page_size);
+3 −3
Original line number Original line Diff line number Diff line
@@ -1573,10 +1573,10 @@ static size_t __iommu_unmap(struct iommu_domain *domain,


	if (unlikely(ops->unmap == NULL ||
	if (unlikely(ops->unmap == NULL ||
		     domain->pgsize_bitmap == 0UL))
		     domain->pgsize_bitmap == 0UL))
		return -ENODEV;
		return 0;


	if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
	if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
		return -EINVAL;
		return 0;


	/* find out the minimum page size supported */
	/* find out the minimum page size supported */
	min_pagesz = 1 << __ffs(domain->pgsize_bitmap);
	min_pagesz = 1 << __ffs(domain->pgsize_bitmap);
@@ -1589,7 +1589,7 @@ static size_t __iommu_unmap(struct iommu_domain *domain,
	if (!IS_ALIGNED(iova | size, min_pagesz)) {
	if (!IS_ALIGNED(iova | size, min_pagesz)) {
		pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%x\n",
		pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%x\n",
		       iova, size, min_pagesz);
		       iova, size, min_pagesz);
		return -EINVAL;
		return 0;
	}
	}


	pr_debug("unmap this: iova 0x%lx size 0x%zx\n", iova, size);
	pr_debug("unmap this: iova 0x%lx size 0x%zx\n", iova, size);
+7 −7
Original line number Original line Diff line number Diff line
@@ -465,23 +465,23 @@ static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
	return -ENODEV;
	return -ENODEV;
}
}


static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
static inline size_t iommu_unmap(struct iommu_domain *domain,
			      size_t size)
				 unsigned long iova, size_t size)
{
{
	return -ENODEV;
	return 0;
}
}


static inline int iommu_unmap_fast(struct iommu_domain *domain, unsigned long iova,
static inline size_t iommu_unmap_fast(struct iommu_domain *domain,
				   int gfp_order)
				      unsigned long iova, int gfp_order)
{
{
	return -ENODEV;
	return 0;
}
}


static inline size_t iommu_map_sg(struct iommu_domain *domain,
static inline size_t iommu_map_sg(struct iommu_domain *domain,
				  unsigned long iova, struct scatterlist *sg,
				  unsigned long iova, struct scatterlist *sg,
				  unsigned int nents, int prot)
				  unsigned int nents, int prot)
{
{
	return -ENODEV;
	return 0;
}
}


static inline void iommu_flush_tlb_all(struct iommu_domain *domain)
static inline void iommu_flush_tlb_all(struct iommu_domain *domain)