Skip to content

Commit

Permalink
iommu/arm: Cleanup resources in case of probe error path
Browse files Browse the repository at this point in the history
If device registration fails, remove sysfs attribute
and if setting bus callbacks fails, unregister the device
and cleanup the sysfs attribute.

Signed-off-by: Amey Narkhede <ameynarkhede03@gmail.com>
Link: https://lore.kernel.org/r/20210608164559.204023-1-ameynarkhede03@gmail.com
Signed-off-by: Will Deacon <will@kernel.org>
  • Loading branch information
Amey Narkhede authored and Will Deacon committed Jun 8, 2021
1 parent ab9a77a commit 249c9dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
14 changes: 12 additions & 2 deletions drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -3848,10 +3848,20 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev);
if (ret) {
dev_err(dev, "Failed to register iommu\n");
return ret;
goto err_sysfs_remove;
}

return arm_smmu_set_bus_ops(&arm_smmu_ops);
ret = arm_smmu_set_bus_ops(&arm_smmu_ops);
if (ret)
goto err_unregister_device;

return 0;

err_unregister_device:
iommu_device_unregister(&smmu->iommu);
err_sysfs_remove:
iommu_device_sysfs_remove(&smmu->iommu);
return ret;
}

static int arm_smmu_device_remove(struct platform_device *pdev)
Expand Down
15 changes: 12 additions & 3 deletions drivers/iommu/arm/arm-smmu/arm-smmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
err = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev);
if (err) {
dev_err(dev, "Failed to register iommu\n");
return err;
goto err_sysfs_remove;
}

platform_set_drvdata(pdev, smmu);
Expand All @@ -2187,10 +2187,19 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
* any device which might need it, so we want the bus ops in place
* ready to handle default domain setup as soon as any SMMU exists.
*/
if (!using_legacy_binding)
return arm_smmu_bus_init(&arm_smmu_ops);
if (!using_legacy_binding) {
err = arm_smmu_bus_init(&arm_smmu_ops);
if (err)
goto err_unregister_device;
}

return 0;

err_unregister_device:
iommu_device_unregister(&smmu->iommu);
err_sysfs_remove:
iommu_device_sysfs_remove(&smmu->iommu);
return err;
}

static int arm_smmu_device_remove(struct platform_device *pdev)
Expand Down
13 changes: 11 additions & 2 deletions drivers/iommu/arm/arm-smmu/qcom_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,12 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
ret = iommu_device_register(&qcom_iommu->iommu, &qcom_iommu_ops, dev);
if (ret) {
dev_err(dev, "Failed to register iommu\n");
return ret;
goto err_sysfs_remove;
}

bus_set_iommu(&platform_bus_type, &qcom_iommu_ops);
ret = bus_set_iommu(&platform_bus_type, &qcom_iommu_ops);
if (ret)
goto err_unregister_device;

if (qcom_iommu->local_base) {
pm_runtime_get_sync(dev);
Expand All @@ -862,6 +864,13 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
}

return 0;

err_unregister_device:
iommu_device_unregister(&qcom_iommu->iommu);

err_sysfs_remove:
iommu_device_sysfs_remove(&qcom_iommu->iommu);
return ret;
}

static int qcom_iommu_device_remove(struct platform_device *pdev)
Expand Down

0 comments on commit 249c9dc

Please sign in to comment.