Skip to contentSkip to conversation

clk: tenstorrent: Fix refcount leak on shared gate clk enable failure

PATCH Applied Anirudh Srinivasan 2 participants 3 messages Sep 24 – Sep 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: tenstorrent: Fix refcount leak on shared gate clk enable failure

atlantis_clk_gate_shared_enable() increments the refcount for the number of clks requesting the shared gate clk to be enabled always. It should only do this when the enable for the gate took effect in hardware. It's possible to end up in a situation where the gate enable failed, but the refcount is incremented anyway, so subsequent requests by other clks that share the same refcount get ignored and the gate enable is never retried.

Update this function so that the refcount is not incremented when the gate clk enable fails in hardware.

---
 drivers/clk/tenstorrent/atlantis-prcm.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/clk/tenstorrent/atlantis-prcm.c +9 -10
index 6d4386eeb7dae..c8663b973749c 100644
@@ -397,22 +397,21 @@ static int atlantis_clk_gate_shared_enable(struct clk_hw *hw)
 
 	scoped_guard(spinlock_irqsave, gate->config.refcount_lock)
 	{
-		need_enable = (*gate->config.share_count)++ == 0;
+		need_enable = (*gate->config.share_count) == 0;
 		if (need_enable) {
 			regmap_set_bits(gate->common.regmap,
 					gate->config.reg_offset,
 					gate->config.enable);
-		}
-	}
 
-	if (need_enable) {
-		if (!regmap_test_bits(gate->common.regmap,
-				      gate->config.reg_offset,
-				      gate->config.enable)) {
-			pr_warn("%s: gate enable %d failed to enable\n",
-				clk_hw_get_name(hw), gate->config.enable);
-			return -EIO;
+			if (!regmap_test_bits(gate->common.regmap,
+					      gate->config.reg_offset,
+					      gate->config.enable)) {
+				pr_warn("%s: gate enable %d failed to enable\n",
+					clk_hw_get_name(hw), gate->config.enable);
+				return -EIO;
+			}
 		}
+		(*gate->config.share_count)++;
 	}
 
 	return 0;

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260924-atlantis_gate_shared_enable_fix-c8d0c8db63ad

Best regards,

Signature · 1 line
Anirudh Srinivasan <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Anirudh Srinivasan

atlantis_clk_gate_shared_enable() increments the refcount for the number of clks requesting the shared gate clk to be enabled always. It should only do this when the enable for the gate took effect in hardware. It's possible to end up in a situation where the gate enable failed, but the refcount is incremented anyway, so subsequent requests by other clks that share the same refcount get ignored and the gate enable is never retried.

Update this function so that the refcount is not incremented when the gate clk enable fails in hardware.

Quoted 7 lines
---
 drivers/clk/tenstorrent/atlantis-prcm.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

I will apply this to tenstorrent-clk-for-next.

Thanks,
Drew

Applied
#2 lore raw
Quoted 20 lines · Drew Fustini
Quoted 11 lines · Anirudh Srinivasan

atlantis_clk_gate_shared_enable() increments the refcount for the number of clks requesting the shared gate clk to be enabled always. It should only do this when the enable for the gate took effect in hardware. It's possible to end up in a situation where the gate enable failed, but the refcount is incremented anyway, so subsequent requests by other clks that share the same refcount get ignored and the gate enable is never retried.

Update this function so that the refcount is not incremented when the gate clk enable fails in hardware.

Quoted 7 lines
---
 drivers/clk/tenstorrent/atlantis-prcm.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
Quoted 3 lines

I will apply this to tenstorrent-clk-for-next.

Applied to tenstorrent-clk-for-next:

3f0655b51eb0 clk: tenstorrent: Fix refcount leak on shared gate clk enable failure

Thanks,
Drew