[PATCH] clk: zynq: Check CPU_2X gate registration before enabling it
Jerome Brunet
jbrunet at baylibre.com
Mon Nov 30 01:09:46 PST 2026
> During early Zynq boot, of_clk_init() invokes zynq_clk_setup() for the
> enabled xlnx,ps7-clkc node. If CPU_2X gate registration fails, for
> example on allocation failure, clk_register_gate() returns an error
> pointer. clk_prepare_enable() passes it to clk_prepare(), which
> dereferences it before the driver's registration check can report the
> failure.
>
> Check the CPU_2X registration result before enabling the gate. Keep
> the early enable for a valid gate and let the existing registration
> check report a failed gate before the clock provider is published.
>
> Static control-flow review, an
> ARM multi_v7_defconfig build of drivers/clk/zynq/, git diff --check,
> and checkpatch.pl passed. Runtime and hardware reproduction were not
> performed.
>
> Fixes: 3dccfecdb867 ("clk: zynq: Force CPU_2X clock to be ungated")
> Signed-off-by: Jiawen Liu <liu1298662399 at gmail.com>
> ---
> drivers/clk/zynq/clkc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 777187744f4e..2464abb2dc83 100644
> --- a/drivers/clk/zynq/clkc.c
> +++ b/drivers/clk/zynq/clkc.c
> @@ -305,7 +305,8 @@ static void __init zynq_clk_setup(struct device_node *np)
> clks[cpu_2x] = clk_register_gate(NULL, clk_output_name[cpu_2x],
> "cpu_2x_div", CLK_IGNORE_UNUSED, SLCR_ARM_CLK_CTRL,
> 26, 0, &armclk_lock);
> - clk_prepare_enable(clks[cpu_2x]);
> + if (!IS_ERR(clks[cpu_2x]))
> + clk_prepare_enable(clks[cpu_2x]);
This registration surely needs fixing but what you are proposing here is
incomplete: if you check the gate registration then divider and mux should
be checked too.
While at it clk_prepare_enable() should away. CLK_IS_CRITICAL is likely more
approriate. Registration should also stop using global names.
--
Jerome
More information about the linux-arm-kernel
mailing list