[PATCH v1 5/9] iommu/tegra: gart: Clean up driver probe failure unwinding
From: Dmitry Osipenko
Date: Tue May 08 2018 - 14:20:19 EST
Properly clean up allocated resources on driver probe failure.
Signed-off-by: Dmitry Osipenko <digetx@xxxxxxxxx>
---
drivers/iommu/tegra-gart.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index 08e0de4087d1..39305224c48d 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -466,8 +466,7 @@ static int tegra_gart_probe(struct platform_device *pdev)
ret = iommu_device_register(&gart->iommu);
if (ret) {
dev_err(dev, "Failed to register IOMMU\n");
- iommu_device_sysfs_remove(&gart->iommu);
- return ret;
+ goto remove_sysfs;
}
gart->dev = &pdev->dev;
@@ -483,7 +482,8 @@ static int tegra_gart_probe(struct platform_device *pdev)
gart->savedata = vmalloc(sizeof(u32) * gart->page_count);
if (!gart->savedata) {
dev_err(dev, "failed to allocate context save area\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto iommu_unregister;
}
platform_set_drvdata(pdev, gart);
@@ -493,6 +493,13 @@ static int tegra_gart_probe(struct platform_device *pdev)
tegra_mc_register_gart(&gart->mc_gart_handle);
return 0;
+
+iommu_unregister:
+ iommu_device_unregister(&gart->iommu);
+remove_sysfs:
+ iommu_device_sysfs_remove(&gart->iommu);
+
+ return ret;
}
static const struct dev_pm_ops tegra_gart_pm_ops = {
--
2.17.0