Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Heiko Stuebner <heiko@sntech.de>
To: lee@kernel.org, Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Thomas Abraham <thomas.ab@samsung.com>,
	Doug Anderson <dianders@chromium.org>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	Lee Jones <lee@kernel.org>
Cc: stable@vger.kernel.org
Subject: Re: [PATCH 05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier
Date: Sun, 29 Nov 2026 17:42:17 +0100	[thread overview]
Message-ID: <mv1weFx4Tu6q87HJMrFzKA@sntech.de> (raw)
In-Reply-To: <20261127192620.3443537-6-lee@kernel.org>

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@vger.kernel.org
> Signed-off-by: Lee Jones <lee@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



  reply	other threads:[~2026-11-29 16:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261127192620.3443537-1-lee@kernel.org>
2026-11-27 19:25 ` [PATCH 01/10] clk: ti: fapll: Fix output clock array allocation and bounds check Lee Jones
2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
2026-11-27 19:25 ` [PATCH 03/10] clk: starfive: jh7110-sys: Use devres for PLL0 clock and notifier Lee Jones
2026-11-27 19:25 ` [PATCH 04/10] clk: starfive: jh7110: Duplicate top clock bulk arrays per device Lee Jones
2026-11-27 19:25 ` [PATCH 05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier Lee Jones
2026-11-29 16:42   ` Heiko Stuebner [this message]
2026-11-27 19:25 ` [PATCH 06/10] clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate() Lee Jones
2026-11-27 19:25 ` [PATCH 07/10] clk: rp1: Propagate determine_rate() return value for PLL dividers Lee Jones
2026-11-27 19:25 ` [PATCH 08/10] clk: rp1: Reference secondary PLL divider clk_hw in parent tables Lee Jones
2026-11-27 19:25 ` [PATCH 09/10] clk: keystone: sci-clk: Check allocation failure before copying clock array Lee Jones
2026-11-27 19:25 ` [PATCH 10/10] clk: versatile: icst: Check kasprintf() and put parent node on error Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mv1weFx4Tu6q87HJMrFzKA@sntech.de \
    --to=heiko@sntech.de \
    --cc=bmasney+clk@redhat.com \
    --cc=dianders@chromium.org \
    --cc=jbrunet+clk@baylibre.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=sboyd@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=thomas.ab@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox