[PATCH] clk: renesas: rzg2l: Don't mark a coupled clock enabled if enabling fails
From: Suyuan Wang via B4 Relay
Date: Sat Nov 21 2026 - 05:45:26 EST
From: Suyuan Wang <stevewong@xxxxxxxxxxx>
For coupled clocks, rzg2l_mod_clock_enable() sets clock->enabled before
it touches the hardware, so that the sibling can see it:
clock->enabled = true;
...
return rzg2l_mod_clock_endisable(hw, true);
If rzg2l_mod_clock_endisable() then fails, for example because polling
the CLK_MON bit times out, the flag stays set. The clock core does not
count the clock as enabled or call its disable callback when enabling
fails, so nothing clears the flag for this failed enable.
A later enable of the sibling then sees the stale flag and returns
success without enabling or checking the hardware. Disabling that
sibling skips the shared clock bit as well, because the failed clock
still looks enabled.
Clear the flag again when enabling fails.
Found with a static analysis tool and checked by hand.
Fixes: 32897e6fff19 ("clk: renesas: rzg2l: Add support to handle coupled clocks")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
Compile tested on arm64 with clang (W=1, no new warnings). I don't have an RZ/G2L board.
---
drivers/clk/renesas/rzg2l-cpg.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/renesas/rzg2l-cpg.c b/drivers/clk/renesas/rzg2l-cpg.c
index dc2bcbab18f1..18c4ed362295 100644
--- a/drivers/clk/renesas/rzg2l-cpg.c
+++ b/drivers/clk/renesas/rzg2l-cpg.c
@@ -2080,10 +2080,11 @@ static int rzg2l_mod_clock_endisable(struct clk_hw *hw, bool enable)
static int rzg2l_mod_clock_enable(struct clk_hw *hw)
{
struct mod_clock *clock = to_mod_clock(hw);
+ struct rzg2l_cpg_priv *priv = clock->priv;
+ unsigned long flags;
+ int ret;
if (clock->sibling) {
- struct rzg2l_cpg_priv *priv = clock->priv;
- unsigned long flags;
bool enabled;
spin_lock_irqsave(&priv->rmw_lock, flags);
@@ -2094,7 +2095,15 @@ static int rzg2l_mod_clock_enable(struct clk_hw *hw)
return 0;
}
- return rzg2l_mod_clock_endisable(hw, true);
+ ret = rzg2l_mod_clock_endisable(hw, true);
+ if (ret && clock->sibling) {
+ /* the clock core will not disable it, so don't count it */
+ spin_lock_irqsave(&priv->rmw_lock, flags);
+ clock->enabled = false;
+ spin_unlock_irqrestore(&priv->rmw_lock, flags);
+ }
+
+ return ret;
}
static void rzg2l_mod_clock_disable(struct clk_hw *hw)