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 v5 14/15] pmdomain: renesas: r8a78000: Add SCMI remapping support
Date: Wed, 18 Nov 2026 20:22:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-221928@kernel.org> (raw)
In-Reply-To: <e6816327da51f9fbeef67f13aac723b891e5042f.1795029012.git.geert+renesas@glider.be>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] pmdomain: renesas: leak of exclusive reset controls in
r8a78000_mdlc_probe()
- [Medium] pmdomain: renesas: leak of scmi_clk_np reference in
r8a78000_mdlc_probe()
- [Low] pmdomain: renesas: mixed scoped_guard() and goto in
r8a78000_mdlc_attach_dev()
--
commit 35d53b7b58584e545d3609ea7bb1ae4726d2bdc8
Author: Geert Uytterhoeven <geert+renesas@glider.be>
pmdomain: renesas: r8a78000: Add SCMI remapping support
This commit extends the R-Car X5H Module Controller driver to remap
hardware power domain, module clock, and reset IDs to SCMI power domains,
clocks, and resets when SCMI firmware support is available.
> diff --git a/drivers/pmdomain/renesas/r8a78000-mdlc.c b/drivers/pmdomain/renesas/r8a78000-mdlc.c
> index 733bf68dab2ce..79f6f1a9ae95d 100644
> --- a/drivers/pmdomain/renesas/r8a78000-mdlc.c
> +++ b/drivers/pmdomain/renesas/r8a78000-mdlc.c
[ ... ]
> @@ -178,8 +280,148 @@ static int r8a78000_mdlc_attach_dev(struct generic_pm_domain *domain,
> return -ENOENT;
> }
>
> - dev_dbg(dev, "Ignoring HW module 0x%x\n", id);
> + if (!priv->scmi_clk_np) {
> + dev_dbg(dev, "Ignoring HW module 0x%x\n", id);
> + return 0;
> + }
> +
> + entry = &priv->mod_map->entries[idx];
> + dev_dbg(dev, "Mapping HW module 0x%x to SCMI clock %d fck parent %d\n",
> + id, entry->fw_id, entry->fw_fck_parent);
> +
> + clk = scmi_get_clk(dev, priv->scmi_clk_np, entry->fw_id);
> + if (IS_ERR(clk))
> + return PTR_ERR(clk);
> +
> + parent = scmi_get_clk(dev, priv->scmi_clk_np, entry->fw_fck_parent);
> + if (IS_ERR(parent)) {
> + ret = PTR_ERR(parent);
> + goto fail_put_clk;
> + }
> +
> + if (!clk && !parent) {
> + /* Ignore missing SCMI clocks */
> + return 0;
> + }
> +
> + ret = pm_clk_create(dev);
> + if (ret)
> + goto fail_put_parent;
> +
> + if (parent) {
> + ret = pm_clk_add_clk(dev, parent);
> + if (ret) {
> + pm_clk_destroy(dev);
> + goto fail_put_parent;
> + }
> + }
> + if (clk) {
> + ret = pm_clk_add_clk(dev, clk);
> + if (ret) {
> + pm_clk_destroy(dev);
> + goto fail_put_clk;
> + }
> + }
> return 0;
> +
> +fail_put_parent:
> + clk_put(parent);
> +fail_put_clk:
> + clk_put(clk);
> + return ret;
> +}
[Severity: Low]
This isn't a bug, but r8a78000_mdlc_attach_dev() already uses
scoped_guard(mutex, &r8a78000_mdlc_lock), and adding goto-based error
unwinding in the same function mixes cleanup.h helpers with goto labels.
Factoring either the list lookup or the PM clock setup into a helper
would keep them separate.
[ ... ]
> +static struct reset_control **get_rstcs(struct r8a78000_mdlc_priv *priv,
> + struct fwnode_handle *scmi_reset_fwnode)
> +{
> + const struct mod_id_map *map = priv->mod_map;
> + struct fwnode_reference_args scmi_spec;
> + struct reset_control **rstcs, *rstc;
> + struct device *dev = priv->dev;
> + s16 fw_id;
> +
> + if (!map)
> + return NULL;
> +
> + rstcs = devm_kzalloc_objs(dev, *rstcs, map->size);
> + if (!rstcs)
> + return ERR_PTR(-ENOMEM);
> +
> + for (unsigned int i = 0; i < map->size; i++) {
> + fw_id = map->entries[i].fw_id;
> + if (!scmi_reset_fwnode || fw_id < 0)
> + continue;
> +
> + scmi_spec.fwnode = scmi_reset_fwnode;
> + scmi_spec.nargs = 1;
> + scmi_spec.args[0] = fw_id;
> +
> + rstc = reset_control_get_from_provider_exclusive(&scmi_spec);
> + if (IS_ERR(rstc)) {
> + while (i--)
> + reset_control_put(rstcs[i]);
> +
> + return dev_err_cast_probe(dev, rstc,
> + "Failed to get SCMI reset %u\n", fw_id);
> + }
> +
> + rstcs[i] = rstc;
> + }
> +
> + return rstcs;
> }
[Severity: Medium]
Does r8a78000_mdlc_probe() leak the exclusive reset_control objects in
priv->rstcs if a later registration step fails?
reset_control_get_from_provider_exclusive() returns unmanaged references,
and get_rstcs() only calls reset_control_put() when its own loop fails.
If a subsequent call in r8a78000_mdlc_probe() such as
of_genpd_add_provider_onecell() or devm_reset_controller_register() fails,
the reset controls are leaked and remain marked exclusively acquired, so a
later probe retry will fail with -EBUSY. Registering a
devm_add_action_or_reset() callback in get_rstcs() would release them on
probe failure.
[ ... ]
> @@ -249,6 +500,47 @@ static int r8a78000_mdlc_probe(struct platform_device *pdev)
> priv->dev = dev;
> priv->np = np;
>
> + if (!IS_ENABLED(CONFIG_ARM_SCMI_POWER_DOMAIN) ||
> + !IS_ENABLED(CONFIG_COMMON_CLK_SCMI) ||
> + !IS_ENABLED(CONFIG_RESET_SCMI)) {
> + dev_dbg(dev, "SCMI pmdomain/clock/reset support is disabled\n");
> + goto fallback;
> + }
> +
> + scmi = of_find_compatible_node(NULL, NULL, "arm,scmi");
> + if (!scmi) {
> + dev_dbg(dev, "Cannot find SCMI firmware node\n");
> + goto fallback;
> + }
> +
> + if (!of_device_is_available(scmi)) {
> + dev_dbg(dev, "SCMI firmware node is not available\n");
> + goto fallback;
> + }
> +
> + scmi_power_np = scmi_find_proto(scmi, SCMI_PROTOCOL_POWER);
> + if (!scmi_power_np) {
> + dev_dbg(dev,
> + "Cannot find SCMI power domain management protocol\n");
> + goto fallback;
> + }
> +
> + scmi_clk_np = scmi_find_proto(scmi, SCMI_PROTOCOL_CLOCK);
> + if (!scmi_clk_np) {
> + dev_dbg(dev, "Cannot find SCMI clock management protocol\n");
> + goto fallback;
> + }
> +
> + scmi_reset_np = scmi_find_proto(scmi, SCMI_PROTOCOL_RESET);
> + if (!scmi_reset_np) {
> + dev_dbg(dev, "Cannot find SCMI reset management protocol\n");
> + goto fallback;
> + }
> +
> + priv->scmi_clk_np = scmi_clk_np;
> + info = mdlc_data->fw_info;
> +
> +fallback:
[ ... ]
> @@ -295,11 +604,14 @@ static int r8a78000_mdlc_probe(struct platform_device *pdev)
> return dev_err_probe(dev, ret,
> "Failed to register reset controller\n");
>
> + /* Retained in priv->scmi_clk_np */
> + retain_and_null_ptr(scmi_clk_np);
> +
> return 0;
> }
[Severity: Medium]
Does retain_and_null_ptr(scmi_clk_np) leak the scmi_clk_np device_node
reference when the fallback path is taken after scmi_clk_np has been
found?
If scmi_find_proto(scmi, SCMI_PROTOCOL_CLOCK) succeeds but
scmi_find_proto(scmi, SCMI_PROTOCOL_RESET) returns NULL, probe jumps to
fallback before setting priv->scmi_clk_np = scmi_clk_np, and then
unconditionally clears scmi_clk_np via retain_and_null_ptr(scmi_clk_np)
at the end of r8a78000_mdlc_probe().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795029012.git.geert+renesas@glider.be?part=14
next prev parent reply other threads:[~2026-11-18 20:22 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 19:44 [PATCH v5 00/15] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 01/15] clk: renesas: r8a78000: Merge debug prints in r8a78000_clk_get() Geert Uytterhoeven
2026-11-20 2:57 ` Marek Vasut
2026-11-20 7:56 ` Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 02/15] clk: renesas: r8a78000: Replace sentinel by explicit ID map size Geert Uytterhoeven
2026-11-20 3:02 ` Marek Vasut
2026-11-18 19:44 ` [PATCH v5 03/15] clk: renesas: r8a78000: Shrink IDs to 16 bits Geert Uytterhoeven
2026-11-20 3:04 ` Marek Vasut
2026-11-18 19:44 ` [PATCH v5 04/15] clk: renesas: r8a78000: Add clk_hw to clk_map Geert Uytterhoeven
2026-11-20 3:25 ` Marek Vasut
2026-11-18 19:44 ` [PATCH v5 05/15] clk: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-11-20 3:45 ` Marek Vasut
2026-11-18 19:44 ` [PATCH v5 06/15] reset: Extract __reset_control_get_from_provider() Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 07/15] reset: Add reset_control_get_from_provider_exclusive() Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 08/15] pmdomain: Make genpd_get_from_provider() always return on first match Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 09/15] pmdomain: Make genpd_get_from_provider() return -EPROBE_DEFER Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 10/15] pmdomain: Make genpd_get_from_provider() public Geert Uytterhoeven
2026-11-18 19:44 ` [PATCH v5 11/15] pmdomain: renesas: r8a78000: Drop MDLC name comment Geert Uytterhoeven
2026-11-20 3:35 ` Marek Vasut
2026-11-18 19:45 ` [PATCH v5 12/15] pmdomain: renesas: r8a78000: Replace sentinel by explicit ID map size Geert Uytterhoeven
2026-11-20 3:36 ` Marek Vasut
2026-11-18 19:45 ` [PATCH v5 13/15] pmdomain: renesas: r8a78000: Shrink IDs to 16 bits Geert Uytterhoeven
2026-11-20 3:37 ` Marek Vasut
2026-11-18 19:45 ` [PATCH v5 14/15] pmdomain: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-11-18 20:22 ` sashiko-bot [this message]
2026-11-19 7:48 ` Geert Uytterhoeven
2026-11-18 19:45 ` [PATCH v5 15/15] arm64: dts: renesas: ironhide: Enable SCMI devpd, sys, clock, and reset Geert Uytterhoeven
2026-11-19 14:47 ` [PATCH v5 00/15] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Clément Le Goffic
2026-11-19 23:47 ` Laurent Pinchart
2026-11-20 10:29 ` Clément Le Goffic
2026-11-20 11:10 ` Wolfram Sang
2026-11-20 14:33 ` Clément Le Goffic
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-221928@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.