From: sashiko-bot@kernel.org
To: "Tian Xuechen" <202300460064@mail.sdu.edu.cn>
Cc: linux-clk@vger.kernel.org, wsa+renesas@sang-engineering.com
Subject: Re: [PATCH 1/3] clk: renesas: cpg-mssr: Fix potential stale power-domain provider
Date: Tue, 01 Dec 2026 14:12:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-243457@kernel.org> (raw)
In-Reply-To: <20261201140209.3318099-2-202300460064@mail.sdu.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: renesas: cpg-mssr: dangling cpg_mssr_clk_domain on probe
failure
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] clk: renesas: cpg-mssr: use-after-free in
cpg_mssr_genpd_remove() [1]
--
commit 588c002575bfe98f535dae02a9e0a7095b12b576
Author: Tian Xuechen <202300460064@mail.sdu.edu.cn>
clk: renesas: cpg-mssr: Fix potential stale power-domain provider
This commit registers a devres action to remove the OF power-domain
provider on probe failure before the managed PM domain is removed and
freed.
> diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c
> index 1ed11ce4a04c8..d3b8d9b0387c7 100644
> --- a/drivers/clk/renesas/renesas-cpg-mssr.c
> +++ b/drivers/clk/renesas/renesas-cpg-mssr.c
> @@ -670,6 +670,11 @@ void cpg_mssr_detach_dev(struct generic_pm_domain *unused, struct device *dev)
> pm_clk_destroy(dev);
> }
>
> +static void cpg_mssr_genpd_del_provider(void *data)
> +{
> + of_genpd_del_provider(data);
> +}
> +
> static void cpg_mssr_genpd_remove(void *data)
> {
> pm_genpd_remove(data);
[Severity: Critical]
This problem wasn't introduced by this patch, but can ignoring the return
value of pm_genpd_remove() in cpg_mssr_genpd_remove() [1] cause a
use-after-free on probe failure?
pd is allocated with devm_kzalloc_flex(). If a concurrent consumer has
already attached to the domain before a later step in cpg_mssr_probe()
fails, pm_genpd_remove() returns -EBUSY and leaves genpd linked in
gpd_list and attached to the consumer, while devres proceeds to free pd.
> @@ -708,7 +713,11 @@ static int __init cpg_mssr_add_clk_domain(struct device *dev,
>
> cpg_mssr_clk_domain = pd;
>
> - return of_genpd_add_provider_simple(np, genpd);
> + ret = of_genpd_add_provider_simple(np, genpd);
> + if (ret)
> + return ret;
> +
> + return devm_add_action_or_reset(dev, cpg_mssr_genpd_del_provider, np);
> }
[Severity: Medium]
Does a failure after setting cpg_mssr_clk_domain leave
cpg_mssr_clk_domain pointing to freed memory once devres cleans up pd?
Neither the error paths here nor cpg_mssr_genpd_remove() reset
cpg_mssr_clk_domain to NULL. On R-Car SoCs, SYSC power domains register
cpg_mssr_attach_dev() as their attach_dev callback independently of the
CPG OF provider:
drivers/pmdomain/renesas/rcar-sysc.c:rcar_sysc_pd_setup() {
...
} else {
genpd->attach_dev = cpg_mssr_attach_dev;
genpd->detach_dev = cpg_mssr_detach_dev;
}
...
}
When a device in a SYSC power domain probes after cpg_mssr_probe() fails
(for example in cpg_mssr_reset_controller_register()),
cpg_mssr_attach_dev() sees a non-NULL cpg_mssr_clk_domain, skips the
-EPROBE_DEFER check, and dereferences the freed pd in
cpg_mssr_is_pm_clk():
drivers/clk/renesas/renesas-cpg-mssr.c:cpg_mssr_attach_dev() {
struct cpg_mssr_clk_domain *pd = cpg_mssr_clk_domain;
...
if (!pd) {
dev_dbg(dev, "CPG/MSSR clock domain not yet available\n");
return -EPROBE_DEFER;
}
while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
&clkspec)) {
if (cpg_mssr_is_pm_clk(&clkspec, pd))
goto found;
...
}
Resetting cpg_mssr_clk_domain to NULL in cpg_mssr_genpd_remove(), and
assigning cpg_mssr_clk_domain = pd only after
of_genpd_add_provider_simple() has initialized pd->genpd.dev.of_node,
would avoid exposing an uninitialized or freed domain.
[1] https://sashiko.dev/#/bug/linux-ce947c8f-8c21-42fe-99aa-b65e21eced3d
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201140209.3318099-1-202300460064@mail.sdu.edu.cn?part=1
next prev parent reply other threads:[~2026-12-01 14:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 14:02 [PATCH 0/3] clk: renesas: Unregister power-domain providers on probe failure Tian Xuechen
2026-12-01 14:02 ` [PATCH 1/3] clk: renesas: cpg-mssr: Fix potential stale power-domain provider Tian Xuechen
2026-12-01 14:12 ` sashiko-bot [this message]
2026-12-01 14:02 ` [PATCH 2/3] clk: renesas: rzg2l: " Tian Xuechen
2026-12-01 14:02 ` [PATCH 3/3] clk: renesas: rzv2h: " Tian Xuechen
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-243457@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=202300460064@mail.sdu.edu.cn \
--cc=linux-clk@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wsa+renesas@sang-engineering.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 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.