diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 572f5579d38b..e33df1a676ec 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -868,10 +868,15 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
 static int arm_smmu_init_domain_context(struct iommu_domain *domain,
 					struct arm_smmu_device *smmu)
 {
-	int ret, start;
+	int irq, start, ret = 0;
+	unsigned long flags;
 	struct arm_smmu_domain *smmu_domain = domain->priv;
 	struct arm_smmu_cfg *cfg = &smmu_domain->cfg;
 
+	spin_lock_irqsave(&smmu_domain->lock, flags);
+	if (smmu_domain->smmu)
+		goto out_unlock;
+
 	if (smmu->features & ARM_SMMU_FEAT_TRANS_NESTED) {
 		/*
 		 * We will likely want to change this if/when KVM gets
@@ -890,7 +895,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
 	ret = __arm_smmu_alloc_bitmap(smmu->context_map, start,
 				      smmu->num_context_banks);
 	if (IS_ERR_VALUE(ret))
-		return ret;
+		goto out_unlock;
 
 	cfg->cbndx = ret;
 	if (smmu->version == 1) {
@@ -902,7 +907,22 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
 
 	ACCESS_ONCE(smmu_domain->smmu) = smmu;
 	arm_smmu_init_context_bank(smmu_domain);
+	spin_unlock_irqrestore(&smmu_domain->lock, flags);
+
+	irq = smmu->irqs[smmu->num_global_irqs + cfg->irptndx];
+	ret = request_irq(irq, arm_smmu_context_fault, IRQF_SHARED,
+			  "arm-smmu-context-fault", smmu_domain);
+	if (IS_ERR_VALUE(ret)) {
+		dev_err(smmu->dev, "failed to request context IRQ %d (%u)\n",
+			cfg->irptndx, irq);
+		cfg->irptndx = INVALID_IRPTNDX;
+	}
+
 	return 0;
+
+out_unlock:
+	spin_unlock_irqrestore(&smmu_domain->lock, flags);
+	return ret;
 }
 
 static void arm_smmu_destroy_domain_context(struct iommu_domain *domain)
@@ -1158,12 +1178,10 @@ static void arm_smmu_domain_remove_master(struct arm_smmu_domain *smmu_domain,
 
 static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
 {
-	int irq, ret;
+	int ret;
 	struct arm_smmu_domain *smmu_domain = domain->priv;
 	struct arm_smmu_device *smmu, *dom_smmu;
-	struct arm_smmu_master_cfg *master_cfg;
-	struct arm_smmu_cfg *cfg = &smmu_domain->cfg;
-	unsigned long flags;
+	struct arm_smmu_master_cfg *cfg;
 
 	smmu = dev_get_master_dev(dev)->archdata.iommu;
 	if (!smmu) {
@@ -1171,57 +1189,33 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
 		return -ENXIO;
 	}
 
-	dom_smmu = ACCESS_ONCE(smmu_domain->smmu);
-
 	/*
 	 * Sanity check the domain. We don't support domains across
 	 * different SMMUs.
 	 */
+	dom_smmu = ACCESS_ONCE(smmu_domain->smmu);
 	if (!dom_smmu) {
-		spin_lock_irqsave(&smmu_domain->lock, flags);
-		/*
-		 * make sure we're not racing with someone who might
-		 * have just attached and init'd the domain context
-		 */
-		dom_smmu = smmu_domain->smmu;
-		if (dom_smmu) {
-			spin_unlock_irqrestore(&smmu_domain->lock, flags);
-			goto have_dom_smmu;
-		}
 		/* Now that we have a master, we can finalise the domain */
 		ret = arm_smmu_init_domain_context(domain, smmu);
-		spin_unlock_irqrestore(&smmu_domain->lock, flags);
 		if (IS_ERR_VALUE(ret))
 			return ret;
-		dom_smmu = smmu_domain->smmu;
 
-		irq = smmu->irqs[smmu->num_global_irqs + cfg->irptndx];
-		ret = request_irq(irq, arm_smmu_context_fault, IRQF_SHARED,
-				"arm-smmu-context-fault", domain);
-		if (IS_ERR_VALUE(ret)) {
-			dev_err(smmu->dev, "failed to request context IRQ %d (%u)\n",
-				cfg->irptndx, irq);
-			cfg->irptndx = INVALID_IRPTNDX;
-			return ret;
-		}
+		dom_smmu = smmu_domain->smmu;
 	}
 
-have_dom_smmu:
-
 	if (dom_smmu != smmu) {
 		dev_err(dev,
 			"cannot attach to SMMU %s whilst already attached to domain on SMMU %s\n",
-			dev_name(smmu_domain->smmu->dev),
-			dev_name(smmu->dev));
+			dev_name(smmu_domain->smmu->dev), dev_name(smmu->dev));
 		return -EINVAL;
 	}
 
 	/* Looks ok, so add the device to the domain */
-	master_cfg = find_smmu_master_cfg(smmu_domain->smmu, dev);
-	if (!master_cfg)
+	cfg = find_smmu_master_cfg(smmu_domain->smmu, dev);
+	if (!cfg)
 		return -ENODEV;
 
-	return arm_smmu_domain_add_master(smmu_domain, master_cfg);
+	return arm_smmu_domain_add_master(smmu_domain, cfg);
 }
 
 static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
