Skip to contentSkip to conversation

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

PATCH In review Amey Narkhede 2 participants 3 messages Apr 21, 2021 – Jun 8, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/qcom: 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.

---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +12 -2
index 4294abe389b2..5fa128a1f7f0 100644
@@ -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,14 @@ 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)

--
2.31.1

I assume its ok to leave pm_runtime_enable in case of error.

maintainer
#1 lore raw
Quoted 30 lines · Amey Narkhede

If device registration fails, remove sysfs attribute and if setting bus callbacks fails, unregister the device and cleanup the sysfs attribute.

---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +4 -2
index 4294abe389b2..5fa128a1f7f0 100644
@@ -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,14 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
 	}

drivers/iommu/arm/arm-smmu/qcom_iommu.c static int qcom_iommu_device_probe(struct platform_device *pdev) · line 874

Quoted 10 lines
drivers/iommu/arm/arm-smmu/qcom_iommu.c +8 -0
 
 	return 0;
+
+err_unregister_device:
+	iommu_device_unregister(&qcom_iommu->iommu);
+
+err_sysfs_remove:
+	iommu_device_sysfs_remove(&qcom_iommu->iommu);
+
+	return ret;

It looks like we're also missing this logic in arm-smmu/arm-smmu.c and arm-smmu-v3/arm-smmu-v3.c. Would you be able to fix those up too, please?

Will
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#2 lore raw
Quoted 45 lines · Will Deacon
Quoted 30 lines · Amey Narkhede

If device registration fails, remove sysfs attribute and if setting bus callbacks fails, unregister the device and cleanup the sysfs attribute.

---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu/qcom_iommu.c +4 -2
index 4294abe389b2..5fa128a1f7f0 100644
@@ -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,14 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
 	}

drivers/iommu/arm/arm-smmu/qcom_iommu.c static int qcom_iommu_device_probe(struct platform_device *pdev) · line 874

Quoted 10 lines
drivers/iommu/arm/arm-smmu/qcom_iommu.c +8 -0
 
 	return 0;
+
+err_unregister_device:
+	iommu_device_unregister(&qcom_iommu->iommu);
+
+err_sysfs_remove:
+	iommu_device_sysfs_remove(&qcom_iommu->iommu);
+
+	return ret;

It looks like we're also missing this logic in arm-smmu/arm-smmu.c and arm-smmu-v3/arm-smmu-v3.c. Would you be able to fix those up too, please?

Quoted 1 line

Will

Sure, I will send a v2 with this and new patches.

Thanks,
Amey
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu