]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
clk: scmi: Fix priv initialization in scmi_clk_gate()
authorPatrice Chotard <patrice.chotard@foss.st.com>
Thu, 18 Dec 2025 17:27:02 +0000 (18:27 +0100)
committerPeng Fan <peng.fan@nxp.com>
Mon, 5 Jan 2026 02:04:48 +0000 (10:04 +0800)
In scmi_clk_probe(), in case of CLK_CCF is not enabled, parent private
data is not set, so in scmi_clk_gate(), an uninitialized priv struct is
retrieved.

SCMI request is performed either using scmi_clk_state_in_v1 or
scmi_clk_state_in_v2 struct depending of the unpredictable value of
priv->version which leads to error during SCMI clock enable.

Issue detected on STM32MP157C-DK2 board using the SCMI device tree
stm32mp157c-dk2-scmi.dts.

Fixes: 0619cb32030b ("firmware: scmi: Add clock v3.2 CONFIG_SET support")
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/clk/clk_scmi.c

index f6132178205b156ddfd8d1fcb2aac8fb3ed70967..a4fc4f8da89d5ef3722228fef3881a162ff01a29 100644 (file)
@@ -137,7 +137,7 @@ static int scmi_clk_get_attribute(struct udevice *dev, int clkid, char *name,
 
 static int scmi_clk_gate(struct clk *clk, int enable)
 {
-       struct scmi_clock_priv *priv = dev_get_parent_priv(clk->dev);
+       struct scmi_clock_priv *priv;
        struct scmi_clk_state_in_v1 in_v1 = {
                .clock_id = clk_get_id(clk),
                .attributes = enable,
@@ -156,6 +156,16 @@ static int scmi_clk_gate(struct clk *clk, int enable)
                                             in_v2, out);
        int ret;
 
+       /*
+        * In scmi_clk_probe(), in case of CLK_CCF is set, SCMI clock
+        * version is set in dev's parent priv struct. Otherwise
+        * SCMI clock version is set in dev priv struct.
+        */
+       if (CONFIG_IS_ENABLED(CLK_CCF))
+               priv = dev_get_parent_priv(clk->dev);
+       else
+               priv = dev_get_priv(clk->dev);
+
        ret = devm_scmi_process_msg(clk->dev,
                                    (priv->version < CLOCK_PROTOCOL_VERSION_2_1) ?
                                    &msg_v1 : &msg_v2);