iommu/fsl: Constrain return value of ->attach_dev()
PATCH v2 5/13 iommu/fsl: Constrain return value of ->attach_dev()
Ensure attach_dev() callback functions only return errno values expected from the attach_dev() op. In particular, only return -EINVAL when we are sure that the device is incompatible with the domain.
--- drivers/iommu/fsl_pamu_domain.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/iommu/fsl_pamu_domain.c +8 -4
@@ -258,7 +258,7 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain, liodn =of_get_property (dev->of_node,"fsl,liodn" , &len);if (!liodn) {pr_debug ("missing fsl,liodn property at %pOF\n" , dev->of_node); -return -EINVAL ; +return -ENODEV ; }spin_lock_irqsave (&dma_domain->domain_lock, flags);
@@ -267,17 +267,21 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,if (liodn[i] >=PAACE_NUMBER_ENTRIES ) {pr_debug ("Invalid liodn %d, attach device failed for %pOF\n" , liodn[i], dev->of_node); - ret = -EINVAL ; + ret = -ENODEV ;break ; }attach_device (dma_domain, liodn[i], dev); ret =pamu_set_liodn (dma_domain, dev, liodn[i]); -if (ret) +if (ret) { + ret = -ENODEV ;break ; + } ret =pamu_enable_liodn (liodn[i]); -if (ret) +if (ret) { + ret = -ENODEV ;break ; + } }spin_unlock_irqrestore (&dma_domain->domain_lock, flags);return ret;
Signature · 1 line
2.17.1
PATCH v2 7/13 iommu/ipmmu-vmsa: Constrain return value of ->attach_dev()
Ensure attach_dev() callback functions only return errno values expected from the attach_dev() op. In particular, only return -EINVAL when we are sure that the device is incompatible with the domain.
Also drop any dev_err next to -EINVAL, following the attach_dev op kdocs.
--- drivers/iommu/ipmmu-vmsa.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/iommu/ipmmu-vmsa.c +5 -5
@@ -452,8 +452,10 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)* Find an unused context. */ ret =ipmmu_domain_allocate_context (domain->mmu->root, domain); -if (ret <0 ) +if (ret <0 ) { + ret = -ENOMEM ;return ret; + } domain->context_id = ret;
@@ -462,7 +464,7 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)if (!domain->iop) {ipmmu_domain_free_context (domain->mmu->root, domain->context_id); -return -EINVAL ; +return -ENOMEM ; }ipmmu_domain_setup_context (domain);
@@ -607,7 +609,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,if (!mmu) {dev_err (dev,"Cannot attach to IPMMU\n" ); -return -ENXIO ; +return -ENODEV ; }mutex_lock (&domain->mutex);
@@ -628,8 +630,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,* Something is wrong, we can't attach two devices using * different IOMMUs to the same domain. */ -dev_err (dev,"Can't attach IPMMU %s to domain on IPMMU %s\n" , -dev_name (mmu->dev),dev_name (domain->mmu->dev)); ret = -EINVAL ; }else dev_info (dev,"Reusing IPMMU context %u\n" , domain->context_id);
Signature · 1 line
2.17.1
PATCH v2 9/13 iommu/omap: Constrain return value of ->attach_dev()
In reply to Nicolin ChenEnsure attach_dev() callback functions only return errno values expected from the attach_dev() op. In particular, only return -EINVAL when we are sure that the device is incompatible with the domain.
Also drop any dev_err next to -EINVAL, following the attach_dev op kdocs.
--- drivers/iommu/omap-iommu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/iommu/omap-iommu.c +4 -3
@@ -1464,15 +1464,14 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)if (!arch_data || !arch_data->iommu_dev) {dev_err (dev,"device doesn't have an associated iommu\n" ); -return -EINVAL ; +return -ENODEV ; }spin_lock (&omap_domain->lock);/* only a single client device can be attached to a domain */ if (omap_domain->dev) { -dev_err (dev,"iommu domain is already attached\n" ); - ret = -EBUSY ; + ret = -EINVAL ; goto out; }
@@ -1480,6 +1479,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)if (ret) {dev_err (dev,"failed to allocate required iommu data %d\n" , ret); + ret = -ENODEV ; goto init_fail; }
@@ -1490,6 +1490,7 @@ omap_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) ret =omap_iommu_attach (oiommu, iommu->pgtable);if (ret) {dev_err (dev,"can't get omap iommu: %d\n" , ret); + ret = -ENODEV ; goto attach_fail; }
Signature · 1 line
2.17.1