All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, linux-clk@vger.kernel.org
Subject: Re: [PATCH 05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier
Date: Fri, 27 Nov 2026 19:33:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-238165@kernel.org> (raw)
In-Reply-To: <20261127192620.3443537-6-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] clk: rockchip: leaked notifier in
  rockchip_clk_register_cpuclk_multi_pll() [1]
--

commit 87431f3421888170ed6b1c77970113743924cab9
Author: Lee Jones <lee@kernel.org>

clk: rockchip: cpu: Allocate rate_table before registering notifier

This commit allocates and populates cpuclk->rate_table before calling
clk_notifier_register() in rockchip_clk_register_cpuclk(), and reverses the
error teardown order so the notifier is unregistered before rate_table is
freed.

> diff --git a/drivers/clk/rockchip/clk-cpu.c b/drivers/clk/rockchip/clk-cpu.c
> index eb6b8b878e4db..27d5b6f6987db 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;
>  
> -free_rate_table:
> -	kfree(cpuclk->rate_table);
>  unregister_notifier:
>  	clk_notifier_unregister(clk, &cpuclk->clk_nb);
> +free_rate_table:
> +	kfree(cpuclk->rate_table);
>  free_alt_parent:
>  	clk_disable_unprepare(cpuclk->alt_parent);
>  free_cpuclk:

[Severity: High]
This problem wasn't introduced by this patch, but does
rockchip_clk_register_cpuclk_multi_pll() in the same file also register
cpuclk->clk_nb before allocating cpuclk->rate_table, and leak the notifier
[1] if kmemdup() fails?

drivers/clk/rockchip/clk-cpu.c:rockchip_clk_register_cpuclk_multi_pll() {
    ...
	ret = clk_notifier_register(hw->clk, &cpuclk->clk_nb);
	if (ret) {
		pr_err("%s: failed to register clock notifier for %s\n",
		       __func__, name);
		goto free_cpuclk;
	}

	if (nrates > 0) {
		cpuclk->rate_count = nrates;
		cpuclk->rate_table = kmemdup(rates,
					     sizeof(*rates) * nrates,
					     GFP_KERNEL);
		if (!cpuclk->rate_table) {
			ret = -ENOMEM;
			goto free_cpuclk;
		}
	}

	return hw->clk;

free_cpuclk:
	kfree(cpuclk);
    ...
}

Jumping directly to free_cpuclk without calling clk_notifier_unregister()
leaves the freed cpuclk->clk_nb linked in clk_notifier_list, which can cause
a use-after-free or list corruption when the notifier chain is later
traversed or modified.

[1] https://sashiko.dev/#/bug/linux-1bafb3ff-a5b6-4219-9489-1455c756f137

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127192620.3443537-1-lee@kernel.org?part=5

  reply	other threads:[~2026-11-27 19:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 19:25 [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Lee Jones
2026-11-27 19:25 ` Lee Jones
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:36   ` sashiko-bot
2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
2026-11-27 19:36   ` sashiko-bot
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-27 19:25   ` Lee Jones
2026-11-27 19:33   ` sashiko-bot [this message]
2026-11-29 16:42   ` Heiko Stuebner
2026-11-29 16:42     ` Heiko Stuebner
2026-11-30 14:51     ` Lee Jones
2026-11-30 14:51       ` Lee Jones
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=sashiko-outbox-238165@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.