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

Simon Glass sjg at chromium.org
Fri Oct 14 17:56:20 CEST 2022


Hi Patrick,

On Fri, 14 Oct 2022 at 03:34, Patrick Delaunay
<patrick.delaunay at foss.st.com> wrote:
>
> 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);

You should just use device_foreach_child_probe() and get rid of all of
this device_probe(), manually traversing internal DM lists, etc. So
this patch needs fixing too:

aeeb2e6d9c6 clk: support clk tree dump

Do clock devices have children which are not also clocks? That doesn't
seem right.

> +       }
> +       if (clkp) {
>                 parent = clk_get_parent(clkp);
>                 if (!IS_ERR(parent) && depth == -1)
>                         return;
> --
> 2.25.1
>

Regards,
SImon


More information about the U-Boot mailing list