@@ -407,14 +407,28 @@ EXPORT_SYMBOL_GPL(dev_iommu_priv_set);
407407 * Init the dev->iommu and dev->iommu_group in the struct device and get the
408408 * driver probed
409409 */
410- static int iommu_init_device (struct device * dev , const struct iommu_ops * ops )
410+ static int iommu_init_device (struct device * dev )
411411{
412+ const struct iommu_ops * ops ;
412413 struct iommu_device * iommu_dev ;
413414 struct iommu_group * group ;
414415 int ret ;
415416
416417 if (!dev_iommu_get (dev ))
417418 return - ENOMEM ;
419+ /*
420+ * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU
421+ * instances with non-NULL fwnodes, and client devices should have been
422+ * identified with a fwspec by this point. Otherwise, we can currently
423+ * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
424+ * be present, and that any of their registered instances has suitable
425+ * ops for probing, and thus cheekily co-opt the same mechanism.
426+ */
427+ ops = iommu_fwspec_ops (dev -> iommu -> fwspec );
428+ if (!ops ) {
429+ ret = - ENODEV ;
430+ goto err_free ;
431+ }
418432
419433 if (!try_module_get (ops -> owner )) {
420434 ret = - EINVAL ;
@@ -517,22 +531,10 @@ DEFINE_MUTEX(iommu_probe_device_lock);
517531
518532static int __iommu_probe_device (struct device * dev , struct list_head * group_list )
519533{
520- const struct iommu_ops * ops ;
521534 struct iommu_group * group ;
522535 struct group_device * gdev ;
523536 int ret ;
524537
525- /*
526- * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU
527- * instances with non-NULL fwnodes, and client devices should have been
528- * identified with a fwspec by this point. Otherwise, we can currently
529- * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can
530- * be present, and that any of their registered instances has suitable
531- * ops for probing, and thus cheekily co-opt the same mechanism.
532- */
533- ops = iommu_fwspec_ops (dev_iommu_fwspec_get (dev ));
534- if (!ops )
535- return - ENODEV ;
536538 /*
537539 * Serialise to avoid races between IOMMU drivers registering in
538540 * 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
546548 if (dev -> iommu_group )
547549 return 0 ;
548550
549- ret = iommu_init_device (dev , ops );
551+ ret = iommu_init_device (dev );
550552 if (ret )
551553 return ret ;
552554
0 commit comments