diff mbox series

clk: xilinx: vcu: rewrite and fix xvcu_clk_hw_unregister_leaf

Message ID 20210318144230.3438009-1-m.tretter@pengutronix.de (mailing list archive)
State Under Review
Headers show
Series clk: xilinx: vcu: rewrite and fix xvcu_clk_hw_unregister_leaf | expand

Commit Message

Michael Tretter March 18, 2021, 2:42 p.m. UTC
The xvcu_clk_hw_unregister_leaf function was missing a check if the
clock mux exits before unregistering the clock mux.

Fix the error by rewriting the entire function. The function now first
finds all clocks that are part of the output clock and afterwards
unregisters all found clocks. This avoids mixing the unregister calls
with get_parent calls and makes the code more readable.

Reported-by: Colin Ian King <colin.king@canonical.com>
Fixes: 9c789deea206 ("soc: xilinx: vcu: implement clock provider for output clocks")
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
Hi,

This is a cleanup and rewrite of the function following the issue
reported by Colin [0]. Hopefully, this is going to clear up the
confusion and makes the code easier to follow.

[0] https://lore.kernel.org/kernel-janitors/20210211095700.158960-1-colin.king@canonical.com/

Michael
---
 drivers/clk/xilinx/xlnx_vcu.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/drivers/clk/xilinx/xlnx_vcu.c b/drivers/clk/xilinx/xlnx_vcu.c
index d66b1315114e..266ee797fdb7 100644
--- a/drivers/clk/xilinx/xlnx_vcu.c
+++ b/drivers/clk/xilinx/xlnx_vcu.c
@@ -499,23 +499,22 @@  static struct clk_hw *xvcu_clk_hw_register_leaf(struct device *dev,
 static void xvcu_clk_hw_unregister_leaf(struct clk_hw *hw)
 {
 	struct clk_hw *gate = hw;
-	struct clk_hw *divider;
-	struct clk_hw *mux;
-
-	if (!gate)
-		return;
-
-	divider = clk_hw_get_parent(gate);
-	clk_hw_unregister_gate(gate);
-	if (!divider)
-		return;
-
-	mux = clk_hw_get_parent(divider);
-	clk_hw_unregister_mux(mux);
-	if (!divider)
-		return;
+	struct clk_hw *divider = NULL;
+	struct clk_hw *mux = NULL;
 
-	clk_hw_unregister_divider(divider);
+	/* Get all clocks of this output clock */
+	if (gate)
+		divider = clk_hw_get_parent(gate);
+	if (divider)
+		mux = clk_hw_get_parent(divider);
+
+	/* Unregister clocks of this output clock if they have been found */
+	if (gate)
+		clk_hw_unregister_gate(gate);
+	if (divider)
+		clk_hw_unregister_divider(divider);
+	if (mux)
+		clk_hw_unregister_mux(mux);
 }
 
 static int xvcu_register_clock_provider(struct xvcu_device *xvcu)