[PATCH 05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier
Heiko Stuebner
heiko at sntech.de
Sun Nov 29 08:42:17 PST 2026
Am Freitag, 27. November 2026, 20:25:29 Mitteleuropäische Normalzeit schrieb Lee Jones:
> rockchip_clk_register_cpuclk() registers cpuclk->clk_nb before
> allocating cpuclk->rate_table, and on clk_register() failure frees
> cpuclk->rate_table before unregistering the notifier. A concurrent
> parent rate change can therefore observe a NULL rate_table while
> rate_count is already non-zero, or dereference the freed rate_table
> before clk_notifier_unregister() completes.
>
> Allocate and populate cpuclk->rate_table before calling
> clk_notifier_register(), and reverse the error-path teardown so the
> notifier is unregistered before cpuclk->rate_table is freed.
>
> Fixes: f6fba5f6967d ("clk: rockchip: add new clock-type for the cpuclk")
> Closes: https://sashiko.dev/#/bug/linux-c0f18cf6-69e2-4cc3-8b2b-7b25245ccd06
> Cc: stable at vger.kernel.org
> Signed-off-by: Lee Jones <lee at kernel.org>
> ---
> drivers/clk/rockchip/clk-cpu.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c
> index eb6b8b878e4d..27d5b6f6987d 100644
> --- a/drivers/clk/rockchip/clk-cpu.c
> +++ b/drivers/clk/rockchip/clk-cpu.c
> @@ -360,36 +360,36 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,
> goto free_alt_parent;
> }
>
> - ret = clk_notifier_register(clk, &cpuclk->clk_nb);
> - if (ret) {
> - pr_err("%s: failed to register clock notifier for %s\n",
> - __func__, name);
> - goto free_alt_parent;
> - }
> -
> if (nrates > 0) {
> - cpuclk->rate_count = nrates;
> cpuclk->rate_table = kmemdup_array(rates, nrates, sizeof(*rates),
> GFP_KERNEL);
> if (!cpuclk->rate_table) {
> ret = -ENOMEM;
> - goto unregister_notifier;
> + goto free_alt_parent;
> }
> + cpuclk->rate_count = nrates;
> + }
> +
> + ret = clk_notifier_register(clk, &cpuclk->clk_nb);
> + if (ret) {
> + pr_err("%s: failed to register clock notifier for %s\n",
> + __func__, name);
> + goto free_rate_table;
> }
>
> cclk = clk_register(NULL, &cpuclk->hw);
> if (IS_ERR(cclk)) {
> - pr_err("%s: could not register cpuclk %s\n", __func__, name);
> + pr_err("%s: could not register cpuclk %s\n", __func__, name);
> ret = PTR_ERR(cclk);
> - goto free_rate_table;
> + goto unregister_notifier;
> }
>
> return cclk;
nothing against this patch, but it's interesting that sashiko did not
notice that rockchip_clk_register_cpuclk_multi_pll() has a similar
pattern?
(notifier before ratet-table and rate-count before kmemdup)
Heiko
More information about the Linux-rockchip
mailing list