Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6269d1f authored by Jeremy Gebben's avatar Jeremy Gebben
Browse files

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: default avatarJeremy Gebben <jgebben@codeaurora.org>
parent 6682fce3
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -1545,7 +1545,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))
@@ -1554,23 +1554,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)
	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);