[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20220914051514.10432-1-nicolinc@nvidia.com>
Date: Tue, 13 Sep 2022 22:15:14 -0700
From: Nicolin Chen <nicolinc@...dia.com>
To: <yong.wu@...iatek.com>, <joro@...tes.org>, <will@...nel.org>,
<robin.murphy@....com>, <matthias.bgg@...il.com>
CC: <jgg@...dia.com>, <kevin.tian@...el.com>, <iommu@...ts.linux.dev>,
<linux-mediatek@...ts.infradead.org>,
<linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>
Subject: [PATCH v2 08/13] iommu/mtk: 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/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
Powered by blists - more mailing lists