From: Lee Jones <lee@kernel.org>
To: Heiko Stuebner <heiko@sntech.de>
Cc: 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,
stable@vger.kernel.org
Subject: Re: [PATCH 05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier
Date: Mon, 30 Nov 2026 14:51:38 +0000 [thread overview]
Message-ID: <20261130145138.GB90630@joneslee-mac.roam.internal> (raw)
In-Reply-To: <mv1weFx4Tu6q87HJMrFzKA@sntech.de>
On Sun, 29 Nov 2026, Heiko Stuebner wrote:
> 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?
I have 59 clk fixes to work my way through. Perhaps it's one of those?
--
Lee Jones
next prev parent reply other threads:[~2026-11-30 14:52 UTC|newest]
Thread overview: 6+ 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 ` [PATCH 05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier Lee Jones
2026-11-29 16:42 ` Heiko Stuebner
2026-11-30 14:51 ` Lee Jones [this message]
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=20261130145138.GB90630@joneslee-mac.roam.internal \
--to=lee@kernel.org \
--cc=bmasney+clk@redhat.com \
--cc=dianders@chromium.org \
--cc=heiko@sntech.de \
--cc=jbrunet+clk@baylibre.com \
--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