Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geert Uytterhoeven" <geert@kernel.org>
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 v6 13/14] pmdomain: renesas: r8a78000: Add SCMI remapping support
Date: Fri, 27 Nov 2026 16:40:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-237909@kernel.org> (raw)
In-Reply-To: <21bac4cbc704669700d62351ec8aefe1165b90ce.1795796064.git.geert+renesas@glider.be>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] pmdomain: renesas: NULL deref in r8a78000_mdlc_put_rstcs() on
  error
- [Medium] pmdomain: renesas: device_node leak of scmi_clk_np in
  r8a78000_mdlc_probe()
--

commit 8f10b43c90068feddde62d11d56b7f918de1b8e1
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 firmware
abstractions when SCMI is available.

> diff --git a/drivers/pmdomain/renesas/r8a78000-mdlc.c b/drivers/pmdomain/renesas/r8a78000-mdlc.c
> index 733bf68dab2ce..654c46f581478 100644
> --- a/drivers/pmdomain/renesas/r8a78000-mdlc.c
> +++ b/drivers/pmdomain/renesas/r8a78000-mdlc.c
[ ... ]
> @@ -178,8 +280,165 @@ static int r8a78000_mdlc_attach_dev(struct generic_pm_domain *domain,
[ ... ]
> +static void r8a78000_mdlc_put_rstcs(void *data)
> +{
> +	struct r8a78000_mdlc_priv *priv = data;
> +
> +	for (unsigned int i = priv->mod_map->size; i--; )
> +		reset_control_put(priv->rstcs[i]);
> +}
> +
> +static struct reset_control **r8a78000_mdlc_get_rstcs(
> +					struct r8a78000_mdlc_priv *priv,
> +					struct fwnode_handle *scmi_reset_fwnode)
> +{
> +	const struct mod_id_map *map = priv->mod_map;
> +	struct device *dev = priv->dev;
> +	struct reset_control **rstcs;
> +	int ret;
> +
> +	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++) {
> +		struct fwnode_reference_args scmi_spec;
> +		s16 fw_id = map->entries[i].fw_id;
> +		struct reset_control *rstc;
> +
> +		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;
> +	}
> +
> +	ret = devm_add_action_or_reset(dev, r8a78000_mdlc_put_rstcs, priv);
> +	if (ret)
> +		return dev_err_ptr_probe(dev, ret,
> +					 "Failed to add reset put action\n");
> +
> +	return rstcs;
>  }

[Severity: Medium]
Can r8a78000_mdlc_put_rstcs() dereference a NULL priv->rstcs pointer if
devm_add_action_or_reset() fails?

r8a78000_mdlc_probe() only assigns priv->rstcs after
r8a78000_mdlc_get_rstcs() returns, so calling devm_add_action_or_reset()
before priv->rstcs is set causes the failure path to index priv->rstcs[i]
while priv->rstcs is still NULL and leak the reset controls in rstcs.

[ ... ]

> @@ -249,6 +517,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 +622,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 this leak the scmi_clk_np device_node reference when SCMI_PROTOCOL_RESET
is missing?

If scmi_find_proto(scmi, SCMI_PROTOCOL_CLOCK) succeeds but
scmi_find_proto(scmi, SCMI_PROTOCOL_RESET) returns NULL, probe jumps to
fallback without setting priv->scmi_clk_np, and the unconditional
retain_and_null_ptr(scmi_clk_np) at the end of probe prevents the __free()
cleanup from releasing scmi_clk_np. Using no_free_ptr(scmi_clk_np) when
assigning priv->scmi_clk_np would avoid retaining it on the fallback path.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795796064.git.geert+renesas@glider.be?part=13

  reply	other threads:[~2026-11-27 16:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 16:26 [PATCH v6 00/14] R-Car X5H Ironhide CPG/MDLC SCMI remapping support Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 01/14] clk: renesas: r8a78000: Merge debug prints in r8a78000_clk_get() Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 02/14] clk: renesas: r8a78000: Replace sentinel by explicit ID map size Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 03/14] clk: renesas: r8a78000: Shrink IDs to 16 bits Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 04/14] clk: renesas: r8a78000: Add clk_hw to clk_map Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 05/14] clk: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 06/14] reset: Extract __reset_control_get_from_provider() Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 07/14] reset: Add reset_control_get_from_provider_exclusive() Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 08/14] pmdomain: Make genpd_get_from_provider() return -EPROBE_DEFER Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 09/14] pmdomain: Make genpd_get_from_provider() public Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 10/14] pmdomain: renesas: r8a78000: Drop MDLC name comment Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 11/14] pmdomain: renesas: r8a78000: Replace sentinel by explicit ID map size Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 12/14] pmdomain: renesas: r8a78000: Shrink IDs to 16 bits Geert Uytterhoeven
2026-11-27 16:26 ` [PATCH v6 13/14] pmdomain: renesas: r8a78000: Add SCMI remapping support Geert Uytterhoeven
2026-11-27 16:40   ` sashiko-bot [this message]
2026-11-27 16:26 ` [PATCH v6 14/14] 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-237909@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox