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

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.com


Signed-off-by: default avatarWill Deacon <will@kernel.org>
parent ab9a77a1
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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)
+12 −3
Original line number Diff line number Diff line
@@ -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)
+11 −2
Original line number Diff line number Diff line
@@ -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)