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 <jgebben@codeaurora.org>
This commit is contained in:
Jeremy Gebben 2015-06-16 12:45:31 -06:00 committed by David Keitel
parent 636df566d2
commit ae4721897e

View file

@ -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);