Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev()
@ 2022-09-14  5:15 Nicolin Chen
  2022-09-14  5:15 ` [PATCH v2 07/13] iommu/ipmmu-vmsa: " Nicolin Chen
  2022-09-14  5:15 ` [PATCH v2 09/13] iommu/omap: " Nicolin Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolin Chen @ 2022-09-14  5:15 UTC (permalink / raw)
  To: joro, will, robin.murphy; +Cc: jgg, kevin.tian, iommu, linux-kernel

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.

Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
 drivers/iommu/fsl_pamu_domain.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 011f9ab7f743..a391ac733b5e 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-14  5:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-14  5:15 [PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev() Nicolin Chen
2022-09-14  5:15 ` [PATCH v2 07/13] iommu/ipmmu-vmsa: " Nicolin Chen
2022-09-14  5:15 ` [PATCH v2 09/13] iommu/omap: " Nicolin Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox