Skip to content

Commit

Permalink
iommu: Move more initialization to __iommu_probe_device()
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20200429133712.31431-34-joro@8bytes.org
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
Joerg Roedel committed May 5, 2020
1 parent 3eeeb45 commit 4e8906f
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions drivers/iommu/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -1532,37 +1540,18 @@ 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) {
iommu_group_put(group);
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;

Expand Down

0 comments on commit 4e8906f

Please sign in to comment.