Skip to content

Commit 4e8906f

Browse files
committed
iommu: Move more initialization to __iommu_probe_device()
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 <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Acked-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3eeeb45 commit 4e8906f

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

drivers/iommu/iommu.c

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,19 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
194194
struct iommu_group *group;
195195
int ret;
196196

197+
if (!dev_iommu_get(dev))
198+
return -ENOMEM;
199+
200+
if (!try_module_get(ops->owner)) {
201+
ret = -EINVAL;
202+
goto err_free;
203+
}
204+
197205
iommu_dev = ops->probe_device(dev);
198-
if (IS_ERR(iommu_dev))
199-
return PTR_ERR(iommu_dev);
206+
if (IS_ERR(iommu_dev)) {
207+
ret = PTR_ERR(iommu_dev);
208+
goto out_module_put;
209+
}
200210

201211
dev->iommu->iommu_dev = iommu_dev;
202212

@@ -217,6 +227,12 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
217227
out_release:
218228
ops->release_device(dev);
219229

230+
out_module_put:
231+
module_put(ops->owner);
232+
233+
err_free:
234+
dev_iommu_free(dev);
235+
220236
return ret;
221237
}
222238

@@ -226,14 +242,6 @@ int iommu_probe_device(struct device *dev)
226242
struct iommu_group *group;
227243
int ret;
228244

229-
if (!dev_iommu_get(dev))
230-
return -ENOMEM;
231-
232-
if (!try_module_get(ops->owner)) {
233-
ret = -EINVAL;
234-
goto err_out;
235-
}
236-
237245
ret = __iommu_probe_device(dev, NULL);
238246
if (ret)
239247
goto err_out;
@@ -1532,37 +1540,18 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
15321540

15331541
static int probe_iommu_group(struct device *dev, void *data)
15341542
{
1535-
const struct iommu_ops *ops = dev->bus->iommu_ops;
15361543
struct list_head *group_list = data;
15371544
struct iommu_group *group;
15381545
int ret;
15391546

1540-
if (!dev_iommu_get(dev))
1541-
return -ENOMEM;
1542-
15431547
/* Device is probed already if in a group */
15441548
group = iommu_group_get(dev);
15451549
if (group) {
15461550
iommu_group_put(group);
15471551
return 0;
15481552
}
15491553

1550-
if (!try_module_get(ops->owner)) {
1551-
ret = -EINVAL;
1552-
goto err_free_dev_iommu;
1553-
}
1554-
15551554
ret = __iommu_probe_device(dev, group_list);
1556-
if (ret)
1557-
goto err_module_put;
1558-
1559-
return 0;
1560-
1561-
err_module_put:
1562-
module_put(ops->owner);
1563-
err_free_dev_iommu:
1564-
dev_iommu_free(dev);
1565-
15661555
if (ret == -ENODEV)
15671556
ret = 0;
15681557

0 commit comments

Comments
 (0)