iommu/arm: Cleanup resources in case of probe error path
authorAmey Narkhede <ameynarkhede03@gmail.com>
Tue, 8 Jun 2021 16:45:59 +0000 (22:15 +0530)
committerWill Deacon <will@kernel.org>
Tue, 8 Jun 2021 16:53:13 +0000 (17:53 +0100)
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>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu/arm-smmu.c
drivers/iommu/arm/arm-smmu/qcom_iommu.c

index 9ca9c53..141cb7d 100644 (file)
@@ -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)
index 6f72c4d..88a3023 100644 (file)
@@ -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);
@@ -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)
index 4294abe..b785d9f 100644 (file)
@@ -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);
@@ -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)