* [PATCH v2 08/13] iommu/mtk: Constrain return value of ->attach_dev()
@ 2022-09-14 5:15 Nicolin Chen
0 siblings, 0 replies; only message in thread
From: Nicolin Chen @ 2022-09-14 5:15 UTC (permalink / raw)
To: yong.wu, joro, will, robin.murphy, matthias.bgg
Cc: jgg, kevin.tian, iommu, linux-mediatek, linux-arm-kernel, 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.
Also drop any dev_err next to -EINVAL, following the attach_dev op kdocs.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/mtk_iommu.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 7e363b1f24df..78c31b307ee1 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -655,7 +655,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
region_id = mtk_iommu_get_iova_region_id(dev, data->plat_data);
if (region_id < 0)
- return region_id;
+ return -ENODEV;
bankid = mtk_iommu_get_bank_id(dev, data->plat_data);
mutex_lock(&dom->mutex);
@@ -678,12 +678,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
ret = pm_runtime_resume_and_get(m4udev);
if (ret < 0) {
dev_err(m4udev, "pm get fail(%d) in attach.\n", ret);
+ ret = -ENODEV;
goto err_unlock;
}
ret = mtk_iommu_hw_init(data, bankid);
if (ret) {
pm_runtime_put(m4udev);
+ ret = -ENODEV;
goto err_unlock;
}
bank->m4u_dom = dom;
@@ -693,7 +695,10 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
}
mutex_unlock(&data->mutex);
- return mtk_iommu_config(data, dev, true, region_id);
+ ret = mtk_iommu_config(data, dev, true, region_id);
+ if (ret)
+ ret = -ENODEV;
+ return ret;
err_unlock:
mutex_unlock(&data->mutex);
--
2.17.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-14 5:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 5:15 [PATCH v2 08/13] iommu/mtk: Constrain return value of ->attach_dev() Nicolin Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).