* [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it
@ 2026-11-29 19:25 Jiawen Liu
2026-11-29 19:36 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jiawen Liu @ 2026-11-29 19:25 UTC (permalink / raw)
To: Stephen Boyd, Brian Masney, Jerome Brunet, Michal Simek
Cc: linux-clk, linux-arm-kernel
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@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 777187744f4e5..2464abb2dc831 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]);
clk_register_fixed_factor(NULL, "cpu_1x_div", "cpu_div", 0, 1,
4 + 2 * tmp);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it
2026-11-29 19:25 [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it Jiawen Liu
@ 2026-11-29 19:36 ` sashiko-bot
2026-11-30 2:11 ` Krzysztof Kozlowski
2026-11-30 9:09 ` Jerome Brunet
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-29 19:36 UTC (permalink / raw)
To: Jiawen Liu; +Cc: linux-clk
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: zynq: unguarded clk_prepare_enable() calls in
zynq_clk_setup()
--
commit b6817b1aedc3306a75bfd961fb6e5fec6834a8dd
Author: Jiawen Liu <liu1298662399@gmail.com>
clk: zynq: Check CPU_2X gate registration before enabling it
This commit guards the clk_prepare_enable() call on clks[cpu_2x] in
zynq_clk_setup() with an !IS_ERR() check in case clk_register_gate()
returns an error pointer.
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 777187744f4e5..2464abb2dc831 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]);
>
> clk_register_fixed_factor(NULL, "cpu_1x_div", "cpu_div", 0, 1,
> 4 + 2 * tmp);
[Severity: Medium]
Should the subsequent clk_prepare_enable() calls in zynq_clk_setup() and
zynq_clk_register_fclk() also check for IS_ERR() before enabling their
gates?
When clks[cpu_2x] registration fails due to memory exhaustion,
zynq_clk_setup() continues executing toward the registration check loop at
the end of the function, passing clks[ddr2x], clks[ddr3x], clks[dci],
clks[fclk], clks[dbg_trc] and clks[dbg_apb] directly from
clk_register_gate() to clk_prepare_enable() without !IS_ERR() checks:
drivers/clk/zynq/clkc.c:zynq_clk_setup() {
...
clks[ddr2x] = clk_register_gate(NULL, clk_output_name[ddr2x],
"ddr2x_div", 0, SLCR_DDR_CLK_CTRL, 1, 0, &ddrclk_lock);
clk_prepare_enable(clks[ddr2x]);
...
}
If any of those gate registrations also returns an error pointer,
clk_prepare() dereferences clk->core before reaching the final check loop.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179598033627.2.16472253499057832801.pattern-ext-064.6@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it
2026-11-29 19:25 [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it Jiawen Liu
2026-11-29 19:36 ` sashiko-bot
@ 2026-11-30 2:11 ` Krzysztof Kozlowski
2026-11-30 9:09 ` Jerome Brunet
2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-30 2:11 UTC (permalink / raw)
To: Jiawen Liu
Cc: linux-clk, Jerome Brunet, linux-arm-kernel, Stephen Boyd,
Michal Simek, Brian Masney
On Sun, 29 Nov 2026 19:25:33 +0000, Jiawen Liu wrote:
> 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@gmail.com>
> ---
> drivers/clk/zynq/clkc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
You sent multiple independent patches, to multiple independent
subsystems. The amount of these patches clearly suggest this was
AI generated and most likely not tested.
More importantly, you sent all this work without properly organizing
relevant patches into patchsets. This makes reviewing difficult
and might cause multiple reviewers to address the same issue.
Replying to the entire set is impossible and requires handling each
patch independently, instead of applying or discarding the set.
Maintainers also won't see the bigger picture of your work. Quite
worrying.
Please read kernel documentation BEFORE posting more work. It will
explain you how to identify subsystems, how to organize your work per
subsystem (so a patchset grouping multiple patches with a short cover
letter), how to document the issue discovery method and what was
or was not tested.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it
2026-11-29 19:25 [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it Jiawen Liu
2026-11-29 19:36 ` sashiko-bot
2026-11-30 2:11 ` Krzysztof Kozlowski
@ 2026-11-30 9:09 ` Jerome Brunet
2 siblings, 0 replies; 4+ messages in thread
From: Jerome Brunet @ 2026-11-30 9:09 UTC (permalink / raw)
To: Jiawen Liu
Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Michal Simek,
linux-clk, linux-arm-kernel, Jerome Brunet
> 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@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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-30 9:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 19:25 [PATCH] clk: zynq: Check CPU_2X gate registration before enabling it Jiawen Liu
2026-11-29 19:36 ` sashiko-bot
2026-11-30 2:11 ` Krzysztof Kozlowski
2026-11-30 9:09 ` Jerome Brunet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.