U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: bigunclemax@gmail.com
Cc: bigunclemax@gmail.com, Lukasz Majewski <lukma@denx.de>,
	Sean Anderson <seanga2@gmail.com>, Tom Rini <trini@konsulko.com>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Christian Marangi <ansuelsmth@gmail.com>,
	Marek Vasut <marex@denx.de>,
	Maxim Kochetkov <m.kochetkov@yadro.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	u-boot@lists.denx.de
Subject: [PATCH v1] clk: Only enable the parent clock if the clock was enabled before reparenting
Date: Fri, 29 Aug 2025 11:25:00 +0300	[thread overview]
Message-ID: <20250829082628.623597-2-bigunclemax@gmail.com> (raw)

From: Maksim Kiselev <bigunclemax@gmail.com>

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")
Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
---
 drivers/clk/clk-uclass.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 4f35b90382f..0f6bf3e02ed 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -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);
-- 
2.48.1


             reply	other threads:[~2025-08-29  8:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29  8:25 bigunclemax [this message]
2025-09-01 12:10 ` [PATCH v1] clk: Only enable the parent clock if the clock was enabled before reparenting Miquel Raynal
2025-12-04 19:31 ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250829082628.623597-2-bigunclemax@gmail.com \
    --to=bigunclemax@gmail.com \
    --cc=ansuelsmth@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=lukma@denx.de \
    --cc=m.kochetkov@yadro.com \
    --cc=marex@denx.de \
    --cc=miquel.raynal@bootlin.com \
    --cc=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=seanga2@gmail.com \
    --cc=semen.protsenko@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox