diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 2d07fd1536e9..dd8abee26e6e 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1574,7 +1574,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *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)); ret = -EINVAL; - goto err_disable_clocks; + goto err_destroy_domain_context; } if (!(smmu_domain->attributes & (1 << DOMAIN_ATTR_COHERENT_HTW_DISABLE)) @@ -1583,23 +1583,26 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) "Can't attach: this domain wants coherent htw but %s doesn't support it\n", dev_name(smmu_domain->smmu->dev)); ret = -EINVAL; - goto err_disable_clocks; + goto err_destroy_domain_context; } /* Looks ok, so add the device to the domain */ cfg = find_smmu_master_cfg(dev); if (!cfg) { ret = -ENODEV; - goto err_disable_clocks; + goto err_destroy_domain_context; } ret = arm_smmu_domain_add_master(smmu_domain, cfg); - if (!ret) - dev->archdata.iommu = domain; + if (ret) + goto err_destroy_domain_context; + dev->archdata.iommu = domain; arm_smmu_disable_clocks(smmu); mutex_unlock(&smmu_domain->init_mutex); return ret; +err_destroy_domain_context: + arm_smmu_destroy_domain_context(domain); err_disable_clocks: arm_smmu_disable_clocks(smmu); mutex_unlock(&smmu_domain->init_mutex);