Skip to content

Commit 14891af

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Move the iommu driver sysfs setup into iommu_init/deinit_device()
It makes logical sense that once the driver is attached to the device the sysfs links appear, even if we haven't fully created the group_device or attached the device to a domain. Fix the missing error handling on sysfs creation since iommu_init_device() can trivially handle this. Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent aa09585 commit 14891af

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

drivers/iommu/iommu-sysfs.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ int iommu_device_link(struct iommu_device *iommu, struct device *link)
107107
{
108108
int ret;
109109

110-
if (!iommu || IS_ERR(iommu))
111-
return -ENODEV;
112-
113110
ret = sysfs_add_link_to_group(&iommu->dev->kobj, "devices",
114111
&link->kobj, dev_name(link));
115112
if (ret)
@@ -126,9 +123,6 @@ EXPORT_SYMBOL_GPL(iommu_device_link);
126123

127124
void iommu_device_unlink(struct iommu_device *iommu, struct device *link)
128125
{
129-
if (!iommu || IS_ERR(iommu))
130-
return;
131-
132126
sysfs_remove_link(&link->kobj, "iommu");
133127
sysfs_remove_link_from_group(&iommu->dev->kobj, "devices", dev_name(link));
134128
}

drivers/iommu/iommu.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,16 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops)
356356
goto err_module_put;
357357
}
358358

359+
ret = iommu_device_link(iommu_dev, dev);
360+
if (ret)
361+
goto err_release;
362+
359363
group = ops->device_group(dev);
360364
if (WARN_ON_ONCE(group == NULL))
361365
group = ERR_PTR(-EINVAL);
362366
if (IS_ERR(group)) {
363367
ret = PTR_ERR(group);
364-
goto err_release;
368+
goto err_unlink;
365369
}
366370
dev->iommu_group = group;
367371

@@ -371,6 +375,8 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops)
371375
dev->iommu->attach_deferred = ops->is_attach_deferred(dev);
372376
return 0;
373377

378+
err_unlink:
379+
iommu_device_unlink(iommu_dev, dev);
374380
err_release:
375381
if (ops->release_device)
376382
ops->release_device(dev);
@@ -388,6 +394,8 @@ static void iommu_deinit_device(struct device *dev)
388394

389395
lockdep_assert_held(&group->mutex);
390396

397+
iommu_device_unlink(dev->iommu->iommu_dev, dev);
398+
391399
/*
392400
* release_device() must stop using any attached domain on the device.
393401
* If there are still other devices in the group they are not effected
@@ -462,7 +470,6 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
462470
iommu_group_put(group);
463471

464472
mutex_unlock(&iommu_probe_device_lock);
465-
iommu_device_link(dev->iommu->iommu_dev, dev);
466473

467474
return 0;
468475

@@ -584,8 +591,6 @@ static void iommu_release_device(struct device *dev)
584591
if (!dev->iommu || !group)
585592
return;
586593

587-
iommu_device_unlink(dev->iommu->iommu_dev, dev);
588-
589594
__iommu_group_remove_device(dev);
590595
}
591596

0 commit comments

Comments
 (0)