From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Abel Vesa <abelvesa@kernel.org>, Peng Fan <peng.fan@nxp.com>,
Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Ian Ray" <ian.ray@gehealthcare.com>,
"Hervé Codina" <herve.codina@bootlin.com>,
"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
devicetree@vger.kernel.org,
"Miquel Raynal" <miquel.raynal@bootlin.com>
Subject: [PATCH 1/5] clk: composite: Initialize inner hw clocks during registration
Date: Wed, 21 Oct 2026 15:09:57 +0200 [thread overview]
Message-ID: <20261021-ge-clk-lcm-v1-1-246cc35b5ffb@bootlin.com> (raw)
In-Reply-To: <20261021-ge-clk-lcm-v1-0-246cc35b5ffb@bootlin.com>
The mux, rate and gate clk_hws of a composite are not registered as
clocks on their own. Only the ->clk pointer was set to the composite
clk, but their ->core remained unassigned.
Provider ops may call into clk_hw_* helpers, such as clk_hw_get_flags()
or clk_hw_get_rate() for instance. In these cases, hw->core will be
dereferenced.
The composite callbacks kind of papered with this situation by (almost)
always calling __clk_hw_set_clk() before
use. clk_composite_determine_rate() never did it, but it probably did
not fail because the core likely called callbacks like get_parent() or
recalc_rate() before.
Add a clk_composite_init() callback that sets up the inner core pointers
once for all just after the core clock registration, and before any
other callback call from the core. Thanks to this, each per-callback
assignement can be dropped.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/clk/clk-composite.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
index 11842bce5918..332b38a326fa 100644
--- a/drivers/clk/clk-composite.c
+++ b/drivers/clk/clk-composite.c
@@ -8,14 +8,26 @@
#include <linux/err.h>
#include <linux/slab.h>
+static int clk_composite_init(struct clk_hw *hw)
+{
+ struct clk_composite *composite = to_clk_composite(hw);
+
+ if (composite->mux_hw)
+ __clk_hw_set_clk(composite->mux_hw, hw);
+ if (composite->rate_hw)
+ __clk_hw_set_clk(composite->rate_hw, hw);
+ if (composite->gate_hw)
+ __clk_hw_set_clk(composite->gate_hw, hw);
+
+ return 0;
+}
+
static u8 clk_composite_get_parent(struct clk_hw *hw)
{
struct clk_composite *composite = to_clk_composite(hw);
const struct clk_ops *mux_ops = composite->mux_ops;
struct clk_hw *mux_hw = composite->mux_hw;
- __clk_hw_set_clk(mux_hw, hw);
-
return mux_ops->get_parent(mux_hw);
}
@@ -25,8 +37,6 @@ static int clk_composite_set_parent(struct clk_hw *hw, u8 index)
const struct clk_ops *mux_ops = composite->mux_ops;
struct clk_hw *mux_hw = composite->mux_hw;
- __clk_hw_set_clk(mux_hw, hw);
-
return mux_ops->set_parent(mux_hw, index);
}
@@ -37,8 +47,6 @@ static unsigned long clk_composite_recalc_rate(struct clk_hw *hw,
const struct clk_ops *rate_ops = composite->rate_ops;
struct clk_hw *rate_hw = composite->rate_hw;
- __clk_hw_set_clk(rate_hw, hw);
-
return rate_ops->recalc_rate(rate_hw, parent_rate);
}
@@ -126,10 +134,8 @@ static int clk_composite_determine_rate(struct clk_hw *hw,
req->rate = best_rate;
return 0;
} else if (rate_hw && rate_ops && rate_ops->determine_rate) {
- __clk_hw_set_clk(rate_hw, hw);
return rate_ops->determine_rate(rate_hw, req);
} else if (mux_hw && mux_ops && mux_ops->determine_rate) {
- __clk_hw_set_clk(mux_hw, hw);
return mux_ops->determine_rate(mux_hw, req);
} else {
pr_err("clk: clk_composite_determine_rate function called, but no mux or rate callback set!\n");
@@ -144,8 +150,6 @@ static int clk_composite_set_rate(struct clk_hw *hw, unsigned long rate,
const struct clk_ops *rate_ops = composite->rate_ops;
struct clk_hw *rate_hw = composite->rate_hw;
- __clk_hw_set_clk(rate_hw, hw);
-
return rate_ops->set_rate(rate_hw, rate, parent_rate);
}
@@ -161,9 +165,6 @@ static int clk_composite_set_rate_and_parent(struct clk_hw *hw,
struct clk_hw *mux_hw = composite->mux_hw;
unsigned long temp_rate;
- __clk_hw_set_clk(rate_hw, hw);
- __clk_hw_set_clk(mux_hw, hw);
-
temp_rate = rate_ops->recalc_rate(rate_hw, parent_rate);
if (temp_rate > rate) {
rate_ops->set_rate(rate_hw, rate, parent_rate);
@@ -182,8 +183,6 @@ static int clk_composite_is_enabled(struct clk_hw *hw)
const struct clk_ops *gate_ops = composite->gate_ops;
struct clk_hw *gate_hw = composite->gate_hw;
- __clk_hw_set_clk(gate_hw, hw);
-
return gate_ops->is_enabled(gate_hw);
}
@@ -193,8 +192,6 @@ static int clk_composite_enable(struct clk_hw *hw)
const struct clk_ops *gate_ops = composite->gate_ops;
struct clk_hw *gate_hw = composite->gate_hw;
- __clk_hw_set_clk(gate_hw, hw);
-
return gate_ops->enable(gate_hw);
}
@@ -204,8 +201,6 @@ static void clk_composite_disable(struct clk_hw *hw)
const struct clk_ops *gate_ops = composite->gate_ops;
struct clk_hw *gate_hw = composite->gate_hw;
- __clk_hw_set_clk(gate_hw, hw);
-
gate_ops->disable(gate_hw);
}
@@ -237,6 +232,7 @@ static struct clk_hw *__clk_hw_register_composite(struct device *dev,
hw = &composite->hw;
clk_composite_ops = &composite->ops;
+ clk_composite_ops->init = clk_composite_init;
if (mux_hw && mux_ops) {
if (!mux_ops->get_parent) {
--
2.56.0
next prev parent reply other threads:[~2026-10-21 13:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 13:09 [PATCH 0/5] clk: Use v2 rate calculation on i.MX8MP Miquel Raynal
2026-10-21 13:09 ` Miquel Raynal [this message]
2026-10-21 13:09 ` [PATCH 2/5] clk: Fix v2 rate negotiation with composite clocks Miquel Raynal
2026-10-21 13:09 ` [PATCH 3/5] clk: imx8mp: Allow adjusting the video PLL rates for the LDB clock Miquel Raynal
2026-10-21 13:10 ` [PATCH 4/5] clk: imx8mp: Set v2 rate negociation to LDB and pixel clocks Miquel Raynal
2026-10-21 13:10 ` [PATCH 5/5] arm64: dts: imx8mp: Drop VIDEO_PLL1 assigned rate Miquel Raynal
2026-10-21 14:11 ` [PATCH 0/5] clk: Use v2 rate calculation on i.MX8MP Brian Masney
2026-10-23 14:10 ` Jerome Brunet
2026-10-23 16:32 ` Miquel Raynal
2026-10-26 9:44 ` Jerome Brunet
2026-10-27 8:45 ` Miquel Raynal
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=20261021-ge-clk-lcm-v1-1-246cc35b5ffb@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=Frank.Li@nxp.com \
--cc=abelvesa@kernel.org \
--cc=bmasney+clk@redhat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=ian.ray@gehealthcare.com \
--cc=imx@lists.linux.dev \
--cc=jbrunet+clk@baylibre.com \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=peng.fan@nxp.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
/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
all inboxes | Powered by JetHome®