[PATCH 4/9] iommu/rockchip: Fix error handling in init

Jeffy Chen jeffy.chen at rock-chips.com
Thu Jan 11 00:22:24 PST 2018


It's hard to undo bus_set_iommu() in the error path, so move it to the
end of init call.

Signed-off-by: Jeffy Chen <jeffy.chen at rock-chips.com>
---

 drivers/iommu/rockchip-iommu.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index a05844cabb45..5f141390b4d7 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1247,17 +1247,25 @@ static int __init rk_iommu_init(void)
 
 	of_node_put(np);
 
-	ret = bus_set_iommu(&platform_bus_type, &rk_iommu_ops);
-	if (ret)
-		return ret;
-
 	ret = platform_driver_register(&rk_iommu_domain_driver);
 	if (ret)
 		return ret;
 
 	ret = platform_driver_register(&rk_iommu_driver);
 	if (ret)
-		platform_driver_unregister(&rk_iommu_domain_driver);
+		goto err_unreg_domain_drv;
+
+	ret = bus_set_iommu(&platform_bus_type, &rk_iommu_ops);
+	if (ret)
+		goto err_unreg_iommu_drv;
+
+	return 0;
+
+err_unreg_iommu_drv:
+	platform_driver_unregister(&rk_iommu_driver);
+err_unreg_domain_drv:
+	platform_driver_unregister(&rk_iommu_domain_driver);
+
 	return ret;
 }
 static void __exit rk_iommu_exit(void)
-- 
2.11.0





More information about the Linux-rockchip mailing list