Skip to content

Commit cfb6ee6

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Always destroy the iommu_group during iommu_release_device()
Have release fully clean up the iommu related parts of the struct device, no matter what state they are in. Split the logic so that the three things owned by the iommu core are always cleaned up: - Any attached iommu_group - Any allocated dev->iommu and its contents including a fwsepc - Any attached driver via a struct group_device This fixes a minor bug where a fwspec created without an iommu_group being probed would not be freed. 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 9a10899 commit cfb6ee6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/iommu/iommu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,8 @@ static void __iommu_group_remove_device(struct device *dev)
574574
iommu_deinit_device(dev);
575575
else
576576
dev->iommu_group = NULL;
577-
goto out;
577+
break;
578578
}
579-
WARN(true, "Corrupted iommu_group device_list");
580-
out:
581579
mutex_unlock(&group->mutex);
582580

583581
/* Pairs with the get in iommu_group_add_device() */
@@ -588,10 +586,12 @@ static void iommu_release_device(struct device *dev)
588586
{
589587
struct iommu_group *group = dev->iommu_group;
590588

591-
if (!dev->iommu || !group)
592-
return;
589+
if (group)
590+
__iommu_group_remove_device(dev);
593591

594-
__iommu_group_remove_device(dev);
592+
/* Free any fwspec if no iommu_driver was ever attached */
593+
if (dev->iommu)
594+
dev_iommu_free(dev);
595595
}
596596

597597
static int __init iommu_set_def_domain_type(char *str)

0 commit comments

Comments
 (0)