Commit 249c9dc6 authored by Amey Narkhede's avatar Amey Narkhede Committed by Will Deacon

iommu/arm: Cleanup resources in case of probe error path

If device registration fails, remove sysfs attribute
and if setting bus callbacks fails, unregister the device
and cleanup the sysfs attribute.
Signed-off-by: default avatarAmey Narkhede <ameynarkhede03@gmail.com>
Link: https://lore.kernel.org/r/20210608164559.204023-1-ameynarkhede03@gmail.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent ab9a77a1
...@@ -3848,10 +3848,20 @@ static int arm_smmu_device_probe(struct platform_device *pdev) ...@@ -3848,10 +3848,20 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev);
if (ret) { if (ret) {
dev_err(dev, "Failed to register iommu\n"); 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) static int arm_smmu_device_remove(struct platform_device *pdev)
......
...@@ -2164,7 +2164,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev) ...@@ -2164,7 +2164,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
err = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); err = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev);
if (err) { if (err) {
dev_err(dev, "Failed to register iommu\n"); dev_err(dev, "Failed to register iommu\n");
return err; goto err_sysfs_remove;
} }
platform_set_drvdata(pdev, smmu); platform_set_drvdata(pdev, smmu);
...@@ -2187,10 +2187,19 @@ static int arm_smmu_device_probe(struct platform_device *pdev) ...@@ -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 * 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. * ready to handle default domain setup as soon as any SMMU exists.
*/ */
if (!using_legacy_binding) if (!using_legacy_binding) {
return arm_smmu_bus_init(&arm_smmu_ops); err = arm_smmu_bus_init(&arm_smmu_ops);
if (err)
goto err_unregister_device;
}
return 0; 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) static int arm_smmu_device_remove(struct platform_device *pdev)
......
...@@ -850,10 +850,12 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) ...@@ -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); ret = iommu_device_register(&qcom_iommu->iommu, &qcom_iommu_ops, dev);
if (ret) { if (ret) {
dev_err(dev, "Failed to register iommu\n"); 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) { if (qcom_iommu->local_base) {
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
...@@ -862,6 +864,13 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) ...@@ -862,6 +864,13 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
} }
return 0; 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) static int qcom_iommu_device_remove(struct platform_device *pdev)
......
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