* [PATCH] clk: Disable parent clock when clk_enable() fails
@ 2026-10-27 18:40 Yuho Choi
2026-10-28 7:36 ` Simon Glass
0 siblings, 1 reply; 2+ messages in thread
From: Yuho Choi @ 2026-10-27 18:40 UTC (permalink / raw)
To: Lukasz Majewski; +Cc: Tom Rini, Peng Fan, u-boot, Yuho Choi
With CONFIG_CLK_CCF, clk_enable() on a clock that is registered by id
and has an enable_count of zero first enables the parent clock if the
parent device is a clock, and only then calls the clock's own enable
op. If that op fails, for example because clk_fracn_gppll_prepare()
returns -ETIMEDOUT when an i.MX93 PLL does not lock, clk_enable()
returns the error without undoing the parent enable.
The enable_count of the clock itself is not incremented in that case, so
a later clk_disable() of it returns early with "already disabled" and
never propagates to the parent. Every failed attempt therefore leaves
the parent's enable_count one higher, and the parent stays enabled even
after all of its real users have disabled it.
Disable the parent again when the enable op fails, the same way
clk_disable() drops the parent reference when the last user of a clock
goes away.
Fixes: 0520be0f67e3 ("clk: prograte clk enable/disable to parent")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
drivers/clk/clk-uclass.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 0069ce9a887..3fc772c8b4f 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -669,7 +669,7 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
int clk_enable(struct clk *clk)
{
const struct clk_ops *ops;
- struct clk *clkp = NULL;
+ struct clk *clkp = NULL, *parent = NULL;
int ret;
debug("%s(clk=%p name=%s)\n", __func__, clk, clk ? clk->dev->name : "NULL");
@@ -687,7 +687,8 @@ int clk_enable(struct clk *clk)
}
if (clkp->dev->parent &&
device_get_uclass_id(clkp->dev->parent) == UCLASS_CLK) {
- ret = clk_enable(dev_get_clk_ptr(clkp->dev->parent));
+ parent = dev_get_clk_ptr(clkp->dev->parent);
+ ret = clk_enable(parent);
if (ret) {
printf("Enable %s failed\n",
clkp->dev->parent->name);
@@ -700,6 +701,8 @@ int clk_enable(struct clk *clk)
ret = ops->enable(clkp ? clkp : clk);
if (ret) {
printf("Enable %s failed\n", clk->dev->name);
+ if (parent)
+ clk_disable(parent);
return ret;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: Disable parent clock when clk_enable() fails
2026-10-27 18:40 [PATCH] clk: Disable parent clock when clk_enable() fails Yuho Choi
@ 2026-10-28 7:36 ` Simon Glass
0 siblings, 0 replies; 2+ messages in thread
From: Simon Glass @ 2026-10-28 7:36 UTC (permalink / raw)
To: oss.patchbox; +Cc: Lukasz Majewski, Tom Rini, Peng Fan, u-boot
On 2026-10-27T18:40:16, Yuho Choi <oss.patchbox@gmail.com> wrote:
> clk: Disable parent clock when clk_enable() fails
>
> With CONFIG_CLK_CCF, clk_enable() on a clock that is registered by id
> and has an enable_count of zero first enables the parent clock if the
> parent device is a clock, and only then calls the clock's own enable
> op. If that op fails, for example because clk_fracn_gppll_prepare()
> returns -ETIMEDOUT when an i.MX93 PLL does not lock, clk_enable()
> returns the error without undoing the parent enable.
>
> The enable_count of the clock itself is not incremented in that case, so
> a later clk_disable() of it returns early with "already disabled" and
> never propagates to the parent. Every failed attempt therefore leaves
> the parent's enable_count one higher, and the parent stays enabled even
> after all of its real users have disabled it.
>
> Disable the parent again when the enable op fails, the same way
> clk_disable() drops the parent reference when the last user of a clock
> goes away.
>
> Fixes: 0520be0f67e3 ("clk: prograte clk enable/disable to parent")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
>
> drivers/clk/clk-uclass.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-28 7:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 18:40 [PATCH] clk: Disable parent clock when clk_enable() fails Yuho Choi
2026-10-28 7:36 ` Simon Glass
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.