Commit a2be6218 authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon

iommu/arm-smmu-v3: Improve add_device() error handling

Let add_device() clean up after itself. The iommu_bus_init() function
does call remove_device() on error, but other sites (e.g. of_iommu) do
not.

Don't free level-2 stream tables because we'd have to track if we
allocated each of them or if they are used by other endpoints. It's not
worth the hassle since they are managed resources.
Reviewed-by: default avatarEric Auger <eric.auger@redhat.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: default avatarWill Deacon <will@kernel.org>
parent d71e0171
...@@ -2821,14 +2821,16 @@ static int arm_smmu_add_device(struct device *dev) ...@@ -2821,14 +2821,16 @@ static int arm_smmu_add_device(struct device *dev)
for (i = 0; i < master->num_sids; i++) { for (i = 0; i < master->num_sids; i++) {
u32 sid = master->sids[i]; u32 sid = master->sids[i];
if (!arm_smmu_sid_in_range(smmu, sid)) if (!arm_smmu_sid_in_range(smmu, sid)) {
return -ERANGE; ret = -ERANGE;
goto err_free_master;
}
/* Ensure l2 strtab is initialised */ /* Ensure l2 strtab is initialised */
if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) {
ret = arm_smmu_init_l2_strtab(smmu, sid); ret = arm_smmu_init_l2_strtab(smmu, sid);
if (ret) if (ret)
return ret; goto err_free_master;
} }
} }
...@@ -2838,13 +2840,25 @@ static int arm_smmu_add_device(struct device *dev) ...@@ -2838,13 +2840,25 @@ static int arm_smmu_add_device(struct device *dev)
master->ssid_bits = min_t(u8, master->ssid_bits, master->ssid_bits = min_t(u8, master->ssid_bits,
CTXDESC_LINEAR_CDMAX); CTXDESC_LINEAR_CDMAX);
ret = iommu_device_link(&smmu->iommu, dev);
if (ret)
goto err_free_master;
group = iommu_group_get_for_dev(dev); group = iommu_group_get_for_dev(dev);
if (!IS_ERR(group)) { if (IS_ERR(group)) {
iommu_group_put(group); ret = PTR_ERR(group);
iommu_device_link(&smmu->iommu, dev); goto err_unlink;
} }
return PTR_ERR_OR_ZERO(group); iommu_group_put(group);
return 0;
err_unlink:
iommu_device_unlink(&smmu->iommu, dev);
err_free_master:
kfree(master);
fwspec->iommu_priv = NULL;
return ret;
} }
static void arm_smmu_remove_device(struct device *dev) static void arm_smmu_remove_device(struct device *dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment