pmdomain: imx: gpcv2: Take a reference to each PGC node
Subsystems (2)
PATCH 1/1 pmdomain: imx: gpcv2: Take a reference to each PGC node
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().
---
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(-)
drivers/pmdomain/imx/gpcv2.c +1 -1
@@ -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
[email protected]
AI reviewThank 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…
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 <[email protected]>
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.
drivers/pmdomain/imx/gpcv2.c static int imx_gpcv2_probe(struct platform_device *pdev) · line 1519
Quoted 13 lines
drivers/pmdomain/imx/gpcv2.c +1
-1@@ -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
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1