[PATCH] clk: renesas: Fix missing unbind on driver look up failure

Marek Vasut marek.vasut+renesas at mailbox.org
Thu Sep 5 00:34:20 CEST 2024


In case lists_driver_lookup_name("rst_gen3") fails, the clk_gen3 driver
has to be unbound before erroring out. Reorder the function such that
both clk_gen3 and rst_gen3 drivers are looked up first, if either look
up fails then the function errors out right away. Second, the clk_gen3
is bound, if binding fails, the function still errors out right away
because there is nothing to undo after either lists_driver_lookup_name()
call. Finally, rst_gen3 is bound and if this binding fails, then that
is the only place where clk_gen3 has to be unbound before erroring out.

Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
 drivers/clk/renesas/clk-rcar-gen3.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/renesas/clk-rcar-gen3.c b/drivers/clk/renesas/clk-rcar-gen3.c
index b84024266f4..ac05788ccc5 100644
--- a/drivers/clk/renesas/clk-rcar-gen3.c
+++ b/drivers/clk/renesas/clk-rcar-gen3.c
@@ -579,23 +579,24 @@ int gen3_cpg_bind(struct udevice *parent)
 	struct cpg_mssr_info *info =
 		(struct cpg_mssr_info *)dev_get_driver_data(parent);
 	struct udevice *cdev, *rdev;
-	struct driver *drv;
+	struct driver *cdrv, *rdrv;
 	int ret;
 
-	drv = lists_driver_lookup_name("clk_gen3");
-	if (!drv)
+	cdrv = lists_driver_lookup_name("clk_gen3");
+	if (!cdrv)
 		return -ENOENT;
 
-	ret = device_bind_with_driver_data(parent, drv, "clk_gen3", (ulong)info,
+
+	rdrv = lists_driver_lookup_name("rst_gen3");
+	if (!rdrv)
+		return -ENOENT;
+
+	ret = device_bind_with_driver_data(parent, cdrv, "clk_gen3", (ulong)info,
 					   dev_ofnode(parent), &cdev);
 	if (ret)
 		return ret;
 
-	drv = lists_driver_lookup_name("rst_gen3");
-	if (!drv)
-		return -ENOENT;
-
-	ret = device_bind_with_driver_data(parent, drv, "rst_gen3", (ulong)cdev,
+	ret = device_bind_with_driver_data(parent, rdrv, "rst_gen3", (ulong)cdev,
 					   dev_ofnode(parent), &rdev);
 	if (ret)
 		device_unbind(cdev);
-- 
2.45.2



More information about the U-Boot mailing list