[PATCH v4 05/17] iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain()

Jason Gunthorpe
2023-04-12T13:51:58Z

This is missing re-attach error handling if the attach fails, use the
common code.

The ugly "group->domain = prev_domain" will be cleaned in a later patch.

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/iommu/iommu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 2b1fc060305ce6..817d90081b4db7 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2964,11 +2964,12 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
if (ret)
goto restore_old_domain;

- ret = iommu_group_create_direct_mappings(group);
+ group->domain = prev_dom;
+ ret = iommu_create_device_direct_mappings(group, dev);
if (ret)
goto free_new_domain;

- ret = __iommu_attach_group(group->default_domain, group);
+ ret = __iommu_group_set_domain(group, group->default_domain);
if (ret)
goto free_new_domain;

@@ -2980,7 +2981,6 @@ static int iommu_change_dev_def_domain(struct iommu_group *group,
iommu_domain_free(group->default_domain);
restore_old_domain:
group->default_domain = prev_dom;
- group->domain = prev_dom;

return ret;
}
--
2.40.0