Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu: Resolve ops in iommu_init_device()

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>

authored by

Robin Murphy and committed by
Joerg Roedel
fd598f71 b46064a1

+16 -14
+16 -14
drivers/iommu/iommu.c
··· 407 407 * Init the dev->iommu and dev->iommu_group in the struct device and get the 408 408 * driver probed 409 409 */ 410 - static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) 410 + static int iommu_init_device(struct device *dev) 411 411 { 412 + const struct iommu_ops *ops; 412 413 struct iommu_device *iommu_dev; 413 414 struct iommu_group *group; 414 415 int ret; 415 416 416 417 if (!dev_iommu_get(dev)) 417 418 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 + } 418 432 419 433 if (!try_module_get(ops->owner)) { 420 434 ret = -EINVAL; ··· 531 517 532 518 static int __iommu_probe_device(struct device *dev, struct list_head *group_list) 533 519 { 534 - const struct iommu_ops *ops; 535 520 struct iommu_group *group; 536 521 struct group_device *gdev; 537 522 int ret; 538 523 539 - /* 540 - * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU 541 - * instances with non-NULL fwnodes, and client devices should have been 542 - * identified with a fwspec by this point. Otherwise, we can currently 543 - * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can 544 - * be present, and that any of their registered instances has suitable 545 - * ops for probing, and thus cheekily co-opt the same mechanism. 546 - */ 547 - ops = iommu_fwspec_ops(dev_iommu_fwspec_get(dev)); 548 - if (!ops) 549 - return -ENODEV; 550 524 /* 551 525 * Serialise to avoid races between IOMMU drivers registering in 552 526 * parallel and/or the "replay" calls from ACPI/OF code via client ··· 548 546 if (dev->iommu_group) 549 547 return 0; 550 548 551 - ret = iommu_init_device(dev, ops); 549 + ret = iommu_init_device(dev); 552 550 if (ret) 553 551 return ret; 554 552