[PATCH] clk: tenstorrent: Fix refcount leak on shared gate clk enable failure

From: Anirudh Srinivasan

Date: Thu Sep 24 2026 - 11:40:43 EST


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.

Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/AS8P251MB00013BD9A093C06D2D60E10EC8B42%40AS8P251MB0001.EURP251.PROD.OUTLOOK.COM
Fixes: 23c8ebc95284 ("clk: tenstorrent: Add Atlantis clock controller driver")
Signed-off-by: Anirudh Srinivasan <asrinivasan@xxxxxxxxxxxxxxxxxxx>
---
drivers/clk/tenstorrent/atlantis-prcm.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/clk/tenstorrent/atlantis-prcm.c b/drivers/clk/tenstorrent/atlantis-prcm.c
index 6d4386eeb7dae..c8663b973749c 100644
--- a/drivers/clk/tenstorrent/atlantis-prcm.c
+++ b/drivers/clk/tenstorrent/atlantis-prcm.c
@@ -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,
--
Anirudh Srinivasan <asrinivasan@xxxxxxxxxxxxxxxxxxx>