summaryrefslogtreecommitdiff
path: root/drivers/iommu/iommu.c
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2023-06-05 21:59:44 -0300
committerJoerg Roedel <jroedel@suse.de>2023-07-14 16:14:14 +0200
commit14891af3799e8cd24dee14f78c31fa663cfb5ba9 (patch)
treeb9f0c432a2e1a298f298fbb8ede494725d059e25 /drivers/iommu/iommu.c
parentaa0958570f24f562422afa41fefd1b3a1fe0f6d0 (diff)
downloadlwn-14891af3799e8cd24dee14f78c31fa663cfb5ba9.tar.gz
lwn-14891af3799e8cd24dee14f78c31fa663cfb5ba9.zip
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 <kevin.tian@intel.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/6-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/iommu.c')
-rw-r--r--drivers/iommu/iommu.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f052f52958fd..4688f61b7a4f 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -356,12 +356,16 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops)
goto err_module_put;
}
+ ret = iommu_device_link(iommu_dev, dev);
+ if (ret)
+ goto err_release;
+
group = ops->device_group(dev);
if (WARN_ON_ONCE(group == NULL))
group = ERR_PTR(-EINVAL);
if (IS_ERR(group)) {
ret = PTR_ERR(group);
- goto err_release;
+ goto err_unlink;
}
dev->iommu_group = group;
@@ -371,6 +375,8 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops)
dev->iommu->attach_deferred = ops->is_attach_deferred(dev);
return 0;
+err_unlink:
+ iommu_device_unlink(iommu_dev, dev);
err_release:
if (ops->release_device)
ops->release_device(dev);
@@ -388,6 +394,8 @@ static void iommu_deinit_device(struct device *dev)
lockdep_assert_held(&group->mutex);
+ iommu_device_unlink(dev->iommu->iommu_dev, dev);
+
/*
* release_device() must stop using any attached domain on the device.
* 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
iommu_group_put(group);
mutex_unlock(&iommu_probe_device_lock);
- iommu_device_link(dev->iommu->iommu_dev, dev);
return 0;
@@ -584,8 +591,6 @@ static void iommu_release_device(struct device *dev)
if (!dev->iommu || !group)
return;
- iommu_device_unlink(dev->iommu->iommu_dev, dev);
-
__iommu_group_remove_device(dev);
}