[PATCH v2 05/13] iommu/fsl: Constrain return value of ->attach_dev()

From: Nicolin Chen
Date: Wed Sep 14 2022 - 01:16:17 EST


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@xxxxxxxxxx>
---
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