From ae4721897e0897127a85ceae9c6b946e70af6e2d Mon Sep 17 00:00:00 2001 From: Jeremy Gebben Date: Tue, 16 Jun 2015 12:45:31 -0600 Subject: [PATCH] iommu/arm-smmu: Tear down domain context if attach fails Currently we're leaving domains half-initialized after a partially-successful attach. Fix this by destroying the domain in the error path. Change-Id: I36c529ed4974c01fba96088b6f57a8e82b350252 Signed-off-by: Jeremy Gebben --- drivers/iommu/arm-smmu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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);