From: sashiko-bot@kernel.org
To: "Geert Uytterhoeven" <geert+renesas@glider.be>
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org,
wsa+renesas@sang-engineering.com
Subject: Re: [PATCH v4 2/8] clk: renesas: r8a78000: Add SCMI remapping support
Date: Fri, 16 Oct 2026 16:13:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-174611@kernel.org> (raw)
In-Reply-To: <c38d744c09dffff550a9b882051c211b572b8daf.1792163045.git.geert+renesas@glider.be>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] clk: memory leak of struct clk and module refcount on success and probe deferral
- [High] clk: renesas: UAF on provider unbind and struct clk memory leak
- [Medium] clk: memory and module refcount leak in fill_clk_map()
--
commit a959fac1d9976d318a861219d6e13c9fef99da15
Author: Geert Uytterhoeven <geert+renesas@glider.be>
clk: renesas: r8a78000: Add SCMI remapping support
This commit extends the Clock Pulse Generator driver for R-Car X5H with SCMI
support. It maps DT clock IDs to abstractions offered by the SCMI firmware,
falling back to fixed-rate clocks if unavailable.
> diff --git a/drivers/clk/renesas/r8a78000-cpg.c b/drivers/clk/renesas/r8a78000-cpg.c
> index 5ffd7b89cb48e..758cfe78ae58e 100644
> --- a/drivers/clk/renesas/r8a78000-cpg.c
> +++ b/drivers/clk/renesas/r8a78000-cpg.c
[ ... ]
> @@ -145,7 +184,46 @@ static const struct clk_map *fill_clk_map(struct r8a78000_cpg_priv *priv,
> break;
>
> map[i].fw_id = map_in[i].fw_id;
> - map[i].hw = fixed_hws[map[i].fw_id];
> + if (map[i].fw_id >= FIXED_CLK_OFFSET) {
> + enum fixed_clk idx = map[i].fw_id - FIXED_CLK_OFFSET;
> +
> + map[i].hw = fixed_hws[idx];
> + continue;
> + }
> +
> + scmi_spec.np = scmi_clk_np;
> + scmi_spec.args_count = 1;
> + scmi_spec.args[0] = map[i].fw_id;
> +
> + clk = of_clk_get_from_provider(&scmi_spec);
> + if (IS_ERR(clk))
> + return dev_err_cast_probe(dev, clk,
> + "Failed to get SCMI clock %u\n", map[i].fw_id);
> +
> + hw = __clk_get_hw(clk);
[Severity: High]
Does this code leak the dynamically allocated struct clk and its module
reference?
of_clk_get_from_provider() returns a new struct clk and increments the
provider's module refcount. The clk pointer is discarded after extracting
the raw clk_hw pointer, so it is never passed to clk_put(). This causes a
memory leak of struct clk objects and a module refcount leak for the SCMI
provider.
If a subsequent clock lookup in the loop fails and returns -EPROBE_DEFER,
the function immediately aborts, and the previously allocated clk handles
from earlier loop iterations are not cleaned up.
Additionally, caching the dangling clk_hw pointer in map[i].hw without holding
a device link or proper reference can lead to a use-after-free. If the SCMI
provider is unbound via sysfs, devres will free the clk_hw structures, but the
CPG driver will still hold and use the stale pointers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1792163045.git.geert+renesas@glider.be?part=2
next prev parent reply other threads:[~2026-10-16 16:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 15:55 [PATCH v4 0/8] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Geert Uytterhoeven
2026-10-16 15:55 ` [PATCH v4 1/8] clk: renesas: r8a78000: Add clk_hw to clk_map Geert Uytterhoeven
2026-10-16 15:55 ` [PATCH v4 2/8] clk: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-10-16 16:13 ` sashiko-bot [this message]
2026-10-16 16:17 ` Geert Uytterhoeven
2026-10-16 15:55 ` [PATCH v4 3/8] reset: Extract __reset_control_get_from_provider() Geert Uytterhoeven
2026-10-16 15:55 ` [PATCH v4 4/8] reset: Add reset_control_get_from_provider_exclusive() Geert Uytterhoeven
2026-10-16 16:02 ` sashiko-bot
2026-10-16 16:08 ` Geert Uytterhoeven
2026-10-16 15:55 ` [PATCH v4 5/8] pmdomain: Make genpd_get_from_provider() return -EPROBE_DEFER Geert Uytterhoeven
2026-10-16 16:09 ` sashiko-bot
2026-10-16 15:55 ` [PATCH v4 6/8] pmdomain: Make genpd_get_from_provider() public Geert Uytterhoeven
2026-10-16 16:08 ` sashiko-bot
2026-10-16 15:55 ` [PATCH v4 7/8] pmdomain: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-10-16 16:15 ` sashiko-bot
2026-10-16 15:55 ` [PATCH v4 8/8] arm64: dts: renesas: ironhide: Enable SCMI devpd, sys, clock, and reset Geert Uytterhoeven
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-174611@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=linux-clk@vger.kernel.org \
--cc=robh@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.