]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu: Resolve ops in iommu_init_device()
authorRobin Murphy <robin.murphy@arm.com>
Fri, 28 Feb 2025 15:46:31 +0000 (15:46 +0000)
committerJoerg Roedel <jroedel@suse.de>
Tue, 11 Mar 2025 13:05:41 +0000 (14:05 +0100)
Since iommu_init_device() was factored out, it is in fact the only
consumer of the ops which __iommu_probe_device() is resolving, so let it
do that itself rather than passing them in. This also puts the ops
lookup at a more logical point relative to the rest of the flow through
__iommu_probe_device().

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/fa4b6cfc67a352488b7f4e0b736008307ce9ac2e.1740753261.git.robin.murphy@arm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu.c

index 5b73d36e43591de86f379ffe8cfc660d2a86f3dd..d26a459f29c32864ab75c364e7de1f811c09126b 100644 (file)
@@ -407,14 +407,28 @@ EXPORT_SYMBOL_GPL(dev_iommu_priv_set);
  * Init the dev->iommu and dev->iommu_group in the struct device and get the
  * driver probed
  */
-static int iommu_init_device(struct device *dev, const struct iommu_ops *ops)
+static int iommu_init_device(struct device *dev)
 {
+       const struct iommu_ops *ops;
        struct iommu_device *iommu_dev;
        struct iommu_group *group;
        int ret;
 
        if (!dev_iommu_get(dev))
                return -ENOMEM;
+       /*
+        * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU
+        * instances with non-NULL fwnodes, and client devices should have been
+        * identified with a fwspec by this point. Otherwise, we can currently
+        * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
+        * be present, and that any of their registered instances has suitable
+        * ops for probing, and thus cheekily co-opt the same mechanism.
+        */
+       ops = iommu_fwspec_ops(dev->iommu->fwspec);
+       if (!ops) {
+               ret = -ENODEV;
+               goto err_free;
+       }
 
        if (!try_module_get(ops->owner)) {
                ret = -EINVAL;
@@ -517,22 +531,10 @@ DEFINE_MUTEX(iommu_probe_device_lock);
 
 static int __iommu_probe_device(struct device *dev, struct list_head *group_list)
 {
-       const struct iommu_ops *ops;
        struct iommu_group *group;
        struct group_device *gdev;
        int ret;
 
-       /*
-        * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU
-        * instances with non-NULL fwnodes, and client devices should have been
-        * identified with a fwspec by this point. Otherwise, we can currently
-        * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
-        * be present, and that any of their registered instances has suitable
-        * ops for probing, and thus cheekily co-opt the same mechanism.
-        */
-       ops = iommu_fwspec_ops(dev_iommu_fwspec_get(dev));
-       if (!ops)
-               return -ENODEV;
        /*
         * Serialise to avoid races between IOMMU drivers registering in
         * parallel and/or the "replay" calls from ACPI/OF code via client
@@ -546,7 +548,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
        if (dev->iommu_group)
                return 0;
 
-       ret = iommu_init_device(dev, ops);
+       ret = iommu_init_device(dev);
        if (ret)
                return ret;