clk: tenstorrent: Fix refcount leak on shared gate clk enable failure
Subsystems (3)
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
@@ -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]>
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
Reported-by Sashiko <[email protected]>Fixes 23c8ebc95284 ("clk: tenstorrent: Add Atlantis clock controller driver")Signed-off-by Anirudh Srinivasan <[email protected]>--- 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
Drew Fustini
AppliedQuoted 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
Reported-by Sashiko <[email protected]>Fixes 23c8ebc95284 ("clk: tenstorrent: Add Atlantis clock controller driver")Signed-off-by Anirudh Srinivasan <[email protected]>--- drivers/clk/tenstorrent/atlantis-prcm.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
Quoted 3 lines
Reviewed-by Drew Fustini (Tenstorrent) <[email protected]>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