[PATCH] cmd: clk: probe the clock before dump them

Patrick Delaunay patrick.delaunay at foss.st.com
Fri Oct 14 11:33:53 CEST 2022


The clock UCLASS need to be probed to allow availability of the
private data (struct clk *), get in show_clks() with dev_get_clk_ptr()
before use them.

Without this patch the clock dump can cause crash because all the
private data are not available before calling the API clk_get_rate().

It is the case for the SCMI clocks, priv->channel is needed for
scmi_clk_get_rate() and it is initialized only in scmi_clk_probe().
This issue causes a crash for "clk dump" command on STM32MP135F-DK board
for SCMI clock not yet probed.

Fixes: 1a725e229096 ("clk: fix clock tree dump to properly dump out every registered clock")
Signed-off-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
---

 cmd/clk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/cmd/clk.c b/cmd/clk.c
index a483fd898122..9c58247935a3 100644
--- a/cmd/clk.c
+++ b/cmd/clk.c
@@ -21,8 +21,11 @@ static void show_clks(struct udevice *dev, int depth, int last_flag)
 	struct clk *clkp, *parent;
 	u32 rate;
 
-	clkp = dev_get_clk_ptr(dev);
-	if (device_get_uclass_id(dev) == UCLASS_CLK && clkp) {
+	clkp = NULL;
+	if (device_get_uclass_id(dev) == UCLASS_CLK && !device_probe(dev)) {
+		clkp = dev_get_clk_ptr(dev);
+	}
+	if (clkp) {
 		parent = clk_get_parent(clkp);
 		if (!IS_ERR(parent) && depth == -1)
 			return;
-- 
2.25.1



More information about the U-Boot mailing list