Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH] pmdomain: imx: gpcv2: Take a reference to each PGC node
@ 2026-11-23 17:19 Yige Jiang
  2026-11-23 17:28 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yige Jiang @ 2026-11-23 17:19 UTC (permalink / raw)
  To: Ulf Hansson, Frank Li
  Cc: Yige Jiang, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	linux-pm, imx, linux-arm-kernel, linux-kernel, Sashiko

The child-node iterator owns the reference to each PGC node, but
imx_gpcv2_probe() assigns the node to a newly allocated platform device
without taking another reference. If platform_device_add() fails,
platform_device_put() releases the node through platform_device_release(),
and the iterator then drops the same reference again.

Use platform_device_set_of_node() to give the child device its own node
reference, paired with the put in platform_device_release().

Fixes: 03aa12629fc4 ("soc: imx: Add GPCv2 power gating driver")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/r/20260530004541.E04701F00898@smtp.kernel.org/
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
AI assistance was used for analysis and patch preparation.

Based on next-20261104 (8b7179210b22).
Compile-tested: arm64, GCC 14.2.0, W=1, drivers/pmdomain/imx/gpcv2.o;
baseline and patched objects built with no warnings.
Static source review; no hardware, boot, or KASAN test was performed.

 drivers/pmdomain/imx/gpcv2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pmdomain/imx/gpcv2.c b/drivers/pmdomain/imx/gpcv2.c
index 6a54ee734514645db7e0628bdddcf579d1f0d904..7b377bf0196491298e9e772b97d15a2bda9ff83a 100644
--- a/drivers/pmdomain/imx/gpcv2.c
+++ b/drivers/pmdomain/imx/gpcv2.c
@@ -1513,7 +1513,7 @@ static int imx_gpcv2_probe(struct platform_device *pdev)
 		domain->genpd.power_off = imx_pgc_power_down;
 
 		pd_pdev->dev.parent = dev;
-		device_set_node(&pd_pdev->dev, of_fwnode_handle(np));
+		platform_device_set_of_node(pd_pdev, np);
 
 		ret = platform_device_add(pd_pdev);
 		if (ret) {

base-commit: 8b7179210b22f8e48a82c5ceacb9d56a9c4cfec4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pmdomain: imx: gpcv2: Take a reference to each PGC node
  2026-11-23 17:19 [PATCH] pmdomain: imx: gpcv2: Take a reference to each PGC node Yige Jiang
@ 2026-11-23 17:28 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 17:28 UTC (permalink / raw)
  To: Yige Jiang; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] pmdomain: imx: gpcv2: use-after-free in imx_gpcv2_probe()
  [1]
--

commit c3636a65fc3cbb73598f1158474f8ad80341a10d
Author: Yige Jiang <yigejiang86@gmail.com>

pmdomain: imx: gpcv2: Take a reference to each PGC node

This commit replaces device_set_node() with platform_device_set_of_node() in
imx_gpcv2_probe() so each child platform device holds its own reference to the
device tree node.

> diff --git a/drivers/pmdomain/imx/gpcv2.c b/drivers/pmdomain/imx/gpcv2.c
> index 6a54ee7345146..7b377bf019649 100644
> --- a/drivers/pmdomain/imx/gpcv2.c
> +++ b/drivers/pmdomain/imx/gpcv2.c
> @@ -1513,7 +1513,7 @@ static int imx_gpcv2_probe(struct platform_device *pdev)
>  		domain->genpd.power_off = imx_pgc_power_down;
>  
>  		pd_pdev->dev.parent = dev;
> -		device_set_node(&pd_pdev->dev, of_fwnode_handle(np));
> +		platform_device_set_of_node(pd_pdev, np);
>  
>  		ret = platform_device_add(pd_pdev);
>  		if (ret) {

[Severity: Critical]
This problem wasn't introduced by this patch, but can returning an error from
this loop [1] leave earlier child pd_pdev devices registered with a
dangling domain->regmap pointer?

When platform_device_add() or platform_device_add_data() fails on a later
child node, imx_gpcv2_probe() returns without unregistering the child platform
devices added in previous iterations.  The failure of imx_gpcv2_probe() then
releases the parent device's devm-managed regmap and MMIO mapping, so any
later power domain operation on the remaining child devices will cause a
use-after-free on domain->regmap.

[1] https://sashiko.dev/#/bug/linux-e1374cb3-5de8-4163-b459-98d74ba7a1e1

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/confirmed-20261105-18-6a8421e1b241@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 17:19 [PATCH] pmdomain: imx: gpcv2: Take a reference to each PGC node Yige Jiang
2026-11-23 17:28 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox