[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20220914051503.10348-2-nicolinc@nvidia.com>
Date: Tue, 13 Sep 2022 22:15:02 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: <joro@...tes.org>, <will@...nel.org>, <robin.murphy@....com>
CC: <jgg@...dia.com>, <kevin.tian@...el.com>, <iommu@...ts.linux.dev>,
<linux-kernel@...r.kernel.org>
Subject: [PATCH v2 07/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.
Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
---
drivers/iommu/ipmmu-vmsa.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 1d42084d0276..73e7d0c261c4 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -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);
--
2.17.1
Powered by blists - more mailing lists