[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200429133712.31431-34-joro@8bytes.org>
Date: Wed, 29 Apr 2020 15:37:11 +0200
From: Joerg Roedel <joro@...tes.org>
To: Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Kukjin Kim <kgene@...nel.org>,
Krzysztof Kozlowski <krzk@...nel.org>,
David Woodhouse <dwmw2@...radead.org>,
Lu Baolu <baolu.lu@...ux.intel.com>,
Andy Gross <agross@...nel.org>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Rob Clark <robdclark@...il.com>,
Heiko Stuebner <heiko@...ech.de>,
Gerald Schaefer <gerald.schaefer@...ibm.com>,
Thierry Reding <thierry.reding@...il.com>,
Jonathan Hunter <jonathanh@...dia.com>,
Jean-Philippe Brucker <jean-philippe@...aro.org>
Cc: Daniel Drake <drake@...lessm.com>, jonathan.derrick@...el.com,
iommu@...ts.linux-foundation.org, linux-kernel@...r.kernel.org,
linux-samsung-soc@...r.kernel.org, linux-arm-msm@...r.kernel.org,
linux-mediatek@...ts.infradead.org,
linux-rockchip@...ts.infradead.org, linux-s390@...r.kernel.org,
linux-tegra@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
Joerg Roedel <jroedel@...e.de>
Subject: [PATCH v3 33/34] iommu: Move more initialization to __iommu_probe_device()
From: Joerg Roedel <jroedel@...e.de>
Move the calls to dev_iommu_get() and try_module_get() into
__iommu_probe_device(), so that the callers don't have to do it on
their own.
Tested-by: Marek Szyprowski <m.szyprowski@...sung.com>
Acked-by: Marek Szyprowski <m.szyprowski@...sung.com>
Signed-off-by: Joerg Roedel <jroedel@...e.de>
---
drivers/iommu/iommu.c | 47 +++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 29 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 7f99e5ae432c..48a95f7d7999 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -194,9 +194,19 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
struct iommu_group *group;
int ret;
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_free;
+ }
+
iommu_dev = ops->probe_device(dev);
- if (IS_ERR(iommu_dev))
- return PTR_ERR(iommu_dev);
+ if (IS_ERR(iommu_dev)) {
+ ret = PTR_ERR(iommu_dev);
+ goto out_module_put;
+ }
dev->iommu->iommu_dev = iommu_dev;
@@ -217,6 +227,12 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
out_release:
ops->release_device(dev);
+out_module_put:
+ module_put(ops->owner);
+
+err_free:
+ dev_iommu_free(dev);
+
return ret;
}
@@ -226,14 +242,6 @@ int iommu_probe_device(struct device *dev)
struct iommu_group *group;
int ret;
- if (!dev_iommu_get(dev))
- return -ENOMEM;
-
- if (!try_module_get(ops->owner)) {
- ret = -EINVAL;
- goto err_out;
- }
-
ret = __iommu_probe_device(dev, NULL);
if (ret)
goto err_out;
@@ -1532,14 +1540,10 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
static int probe_iommu_group(struct device *dev, void *data)
{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
struct list_head *group_list = data;
struct iommu_group *group;
int ret;
- if (!dev_iommu_get(dev))
- return -ENOMEM;
-
/* Device is probed already if in a group */
group = iommu_group_get(dev);
if (group) {
@@ -1547,22 +1551,7 @@ static int probe_iommu_group(struct device *dev, void *data)
return 0;
}
- if (!try_module_get(ops->owner)) {
- ret = -EINVAL;
- goto err_free_dev_iommu;
- }
-
ret = __iommu_probe_device(dev, group_list);
- if (ret)
- goto err_module_put;
-
- return 0;
-
-err_module_put:
- module_put(ops->owner);
-err_free_dev_iommu:
- dev_iommu_free(dev);
-
if (ret == -ENODEV)
ret = 0;
--
2.17.1
Powered by blists - more mailing lists