arm64: dma-mapping: Clean up arm_iommu_attach_device() call flow

Previously the code assumed that iommu_attach_group() would occur after
setting up any dma-specific data structures. But there are several places
where to satisfy this requirement we attach, check some iommu attribute,
and then detach. This is not very clean, so improve it.

Change-Id: I5f115217c892716e3f3911b8177f530a64873267
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
diff --git a/drivers/iommu/dma-mapping-fast.c b/drivers/iommu/dma-mapping-fast.c
index 2c119ac..1ddf0dd 100644
--- a/drivers/iommu/dma-mapping-fast.c
+++ b/drivers/iommu/dma-mapping-fast.c
@@ -870,7 +870,6 @@
 {
 	int err;
 	struct iommu_domain *domain = mapping->domain;
-	struct iommu_group *group;
 	struct iommu_pgtbl_info info;
 	u64 size = (u64)mapping->bits << PAGE_SHIFT;
 
@@ -887,51 +886,26 @@
 
 	fast_smmu_reserve_pci_windows(dev, mapping->fast);
 
-	group = dev->iommu_group;
-	if (!group) {
-		dev_err(dev, "No iommu associated with device\n");
-		err = -ENODEV;
-		goto release_mapping;
-	}
-
-	if (iommu_get_domain_for_dev(dev)) {
-		dev_err(dev, "Device already attached to other iommu_domain\n");
-		err = -EINVAL;
-		goto release_mapping;
-	}
-
-	/*
-	 * Need to attach prior to calling DOMAIN_ATTR_PGTBL_INFO and then
-	 * detach to be in the expected state. Its a bit messy.
-	 */
-	if (iommu_attach_group(mapping->domain, group)) {
-		err = -EINVAL;
-		goto release_mapping;
-	}
-
 	if (iommu_domain_get_attr(domain, DOMAIN_ATTR_PGTBL_INFO,
 				  &info)) {
 		dev_err(dev, "Couldn't get page table info\n");
 		err = -EINVAL;
-		goto detach_group;
+		goto release_mapping;
 	}
 	mapping->fast->pgtbl_pmds = info.pmds;
 
 	if (iommu_domain_get_attr(domain, DOMAIN_ATTR_PAGE_TABLE_IS_COHERENT,
 				  &mapping->fast->is_smmu_pt_coherent)) {
 		err = -EINVAL;
-		goto detach_group;
+		goto release_mapping;
 	}
 
 	mapping->fast->notifier.notifier_call = fast_smmu_notify;
 	av8l_register_notify(&mapping->fast->notifier);
 
-	iommu_detach_group(mapping->domain, group);
 	mapping->ops = &fast_smmu_dma_ops;
 	return 0;
 
-detach_group:
-	iommu_detach_group(mapping->domain, group);
 release_mapping:
 	kfree(mapping->fast->bitmap);
 	kfree(mapping->fast);