Skip to contentSkip to conversation

clk: Only enable the parent clock if the clock was enabled before reparenting

PATCH In review [email protected] 3 participants 3 messages Aug 29, 2025 – Dec 4, 2025 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: Only enable the parent clock if the clock was enabled before reparenting

From: Maksim Kiselev <[email protected]>

The current implementation of clk_set_parent() unconditionally enables the new parent clock, even if the target clock was not previously enabled.

To avoid this implicit behavior, this patch adds a check for whether the target clock has been enabled before parent enabling..

Fixes ac30d90f336 ("clk: Ensure the parent clocks are enabled while reparenting")
---
 drivers/clk/clk-uclass.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/clk/clk-uclass.c +6 -4
index 4f35b90382f..0f6bf3e02ed 100644
@@ -631,10 +631,12 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
 	if (!ops->set_parent)
 		return -ENOSYS;
 
-	ret = clk_enable(parent);
-	if (ret && ret != -ENOSYS) {
-		printf("Cannot enable parent %s\n", parent->dev->name);
-		return ret;
+	if (clk->enable_count) {
+		ret = clk_enable(parent);
+		if (ret && ret != -ENOSYS) {
+			printf("Cannot enable parent %s\n", parent->dev->name);
+			return ret;
+		}
 	}
 
 	ret = ops->set_parent(clk, parent);
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines · On 29/08/2025 at 11:25:00 +03, [email protected] wrote:

From: Maksim Kiselev <[email protected]>

The current implementation of clk_set_parent() unconditionally enables the new parent clock, even if the target clock was not previously enabled.

To avoid this implicit behavior, this patch adds a check for whether the target clock has been enabled before parent enabling..

Fixes ac30d90f336 ("clk: Ensure the parent clocks are enabled while reparenting")

It took me a bit of time to understand your issue, but that sounds legitimate indeed.

Thanks,
Miquèl

#2 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, 29 Aug 2025 11:25:00 +0300, [email protected] wrote:

The current implementation of clk_set_parent() unconditionally enables the new parent clock, even if the target clock was not previously enabled.

To avoid this implicit behavior, this patch adds a check for whether the target clock has been enabled before parent enabling..

[...]

Applied to u-boot/next, thanks!

[1/1] clk: Only enable the parent clock if the clock was enabled before reparenting

      commit: b493db39ea7fb1205d3a2df269352cb79874c1c7
Signature · 1 line
Tom