regulator: as3722: use the platform OF node setter
PATCH 1/1 regulator: as3722: use the platform OF node setter
as3722_get_regulator_dt_data() gets the regulators child node and assigns it only to dev.of_node. Platform device release now puts dev.fwnode, leaving the acquired node reference unreleased.
Use platform_device_set_of_node() to synchronize both fields and give the device its own reference, then put the local lookup reference. This keeps the node valid for regulator matching and the platform device lifetime, while also replacing the previous device-owned reference on a probe retry.
---
Based on linux-next next-20261102 (2637bdec0535).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_OF_DYNAMIC=y. COMPILE_TEST=y.
Baseline and patched target objects built from this exact base. No full kernel/module-link, hardware or runtime test was performed. AI assistance: Codex (LLM) for ownership analysis, code and changelog.
The earlier dangling-node fix is already present in this base.
drivers/regulator/as3722-regulator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/regulator/as3722-regulator.c +2 -1
@@ -596,7 +596,8 @@ static int as3722_get_regulator_dt_data(struct platform_device *pdev,dev_err (&pdev->dev,"Device is not having regulators node\n" );return -ENODEV ; } - pdev->dev.of_node = np; +platform_device_set_of_node (pdev, np); +of_node_put (np); ret =of_regulator_match (&pdev->dev, np, as3722_regulator_matches,ARRAY_SIZE (as3722_regulator_matches));
base-commit: 2637bdec0535a2044cd830eba9a79363651d9043
Quoted 32 lines · Yige Jiang
as3722_get_regulator_dt_data()gets the regulators child node and assigns it only to dev.of_node. Platform device release now puts dev.fwnode, leaving the acquired node reference unreleased.Use
platform_device_set_of_node()to synchronize both fields and give the device its own reference, then put the local lookup reference. This keeps the node valid for regulator matching and the platform device lifetime, while also replacing the previous device-owned reference on a probe retry.Fixes 7b5b51b2b05c ("driver core: platform: count references to all kinds of firmware nodes")Assisted-by LLMSigned-off-by Yige Jiang <[email protected]>---
Based on linux-next next-20261102 (2637bdec0535).
Compile-tested: arm64, GCC 14.2.0, W=1,CONFIG_OF_DYNAMIC=y. COMPILE_TEST=y.
Baseline and patched target objects built from this exact base. No fullkernel/module-link, hardware or runtime test was performed. AI assistance: Codex (LLM) for ownership analysis, code and changelog.The earlier dangling-node fix is already present in this base.
drivers/regulator/as3722-regulator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/regulator/as3722-regulator.c +0
-0
drivers/regulator/as3722-regulator.c static int as3722_get_regulator_dt_data(struct platform_device *pdev, · line 603
Quoted 9 lines
drivers/regulator/as3722-regulator.c +2
-1@@ -596,7 +596,8 @@ static int as3722_get_regulator_dt_data(struct platform_device *pdev,dev_err (&pdev->dev,"Device is not having regulators node\n" );return -ENODEV ; } - pdev->dev.of_node = np; +platform_device_set_of_node (pdev, np); +of_node_put (np); ret =of_regulator_match (&pdev->dev, np, as3722_regulator_matches,ARRAY_SIZE (as3722_regulator_matches));
Same comment as for the other patch, use __free(device_node).
Bart
PATCH v2 1/1 regulator: as3722: use the platform OF node setter
as3722_get_regulator_dt_data() gets the regulators child node and assigns it only to dev.of_node. Platform device release now puts dev.fwnode, leaving the acquired node reference unreleased.
Use platform_device_set_of_node() to synchronize both fields and give the device its own reference. Use __free(device_node) to release the local lookup reference when the function returns. This keeps the node valid for regulator matching and the platform device lifetime, while also replacing the previous device-owned reference on a probe retry.
---
Changes in v2:
- Use __free(device_node) for the local lookup reference, as suggested by Bartosz Golaszewski, instead of an explicit of_node_put().
- Remove the Assisted-by trailer; keep the disclosure below.
Based on linux-next next-20261102 (2637bdec0535).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_OF_DYNAMIC=y. COMPILE_TEST=y.
Baseline and v2 target objects built from this exact base. No full kernel/module-link, hardware or runtime test was performed. AI assistance was used for analysis and patch preparation.
The earlier dangling-node fix is already present in this base.
drivers/regulator/as3722-regulator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/regulator/as3722-regulator.c +3 -3
@@ -585,18 +585,18 @@static int as3722_get_regulator_dt_data (struct platform_device *pdev,struct as3722_regulators *as3722_regs) { -struct device_node *np;struct as3722_regulator_config_data *reg_config;u32 prop;int id;int ret; - np =of_get_child_by_name (pdev->dev.parent->of_node,"regulators" ); + struct device_node *np __free(device_node) = +of_get_child_by_name (pdev->dev.parent->of_node,"regulators" );if (!np) {dev_err (&pdev->dev,"Device is not having regulators node\n" );return -ENODEV ; } - pdev->dev.of_node = np; +platform_device_set_of_node (pdev, np); ret =of_regulator_match (&pdev->dev, np, as3722_regulator_matches,ARRAY_SIZE (as3722_regulator_matches));
base-commit: 2637bdec0535a2044cd830eba9a79363651d9043
Mark Brown
maintainerQuoted 3 lines · Yige Jiang
as3722_get_regulator_dt_data()gets the regulators child node and assigns it only to dev.of_node. Platform device release now puts dev.fwnode, leaving the acquired node reference unreleased.
Please don't send new patches in reply to old patches or serieses, this makes it harder for both people and tools to understand what is going on - it can bury things in mailboxes and make it difficult to keep track of what current patches are, both for the new patches and the old ones.
Quoted 11 lines · Yige Jiang
as3722_get_regulator_dt_data()gets the regulators child node and assigns it only to dev.of_node. Platform device release now puts dev.fwnode, leaving the acquired node reference unreleased.Use
platform_device_set_of_node()to synchronize both fields and give the device its own reference. Use__free(device_node)to release the local lookup reference when the function returns. This keeps the node valid for regulator matching and the platform device lifetime, while also replacing the previous device-owned reference on a probe retry.
Quoted 3 lines
Fixes 7b5b51b2b05c ("driver core: platform: count references to all kinds of firmware nodes")Signed-off-by Yige Jiang <[email protected]>---
As mark said: don't send new versions in response to previous threads.
Mark Brown
maintainerdrivers/regulator/as3722-regulator.c line 599
Quoted 9 lines
Use
platform_device_set_of_node()to synchronize both fields and give the device its own reference. Use__free(device_node)to releasestatic int as3722_get_regulator_dt_data(struct
platform_device*pdev,drivers/regulator/as3722-regulator.c +1
-1struct as3722_regulators *as3722_regs) { - pdev->dev.of_node = np; +platform_device_set_of_node (pdev, np);
Are you sure this is safe to use during probe(), which must of necessity happen after platform_device_add()? In particular with the interactions with fw_devlink.
Signature · 1 line
Mark Brown <[email protected]>
Hi Mark,
You're right, sorry. I overlooked the fw_devlink implications here. I reproduced a probe retry/rebind failure in a controlled QEMU test with the actual driver.
Please drop v2. I have a draft of an alternative fix that I believe would address the reference leak without changing the platform device's node during probe. I'd be happy to post it separately as v3 if that would be helpful.
I also noticed the same probe-time assignment in the applied CPCAP patch and will follow up on that separately.
Thanks,
Yige
Quoted 18 lines · Mark Brown
drivers/regulator/as3722-regulator.c line 599
Quoted 10 lines
Use
platform_device_set_of_node()to synchronize both fields and give the device its own reference. Use__free(device_node)to releasestatic int as3722_get_regulator_dt_data(struct
platform_device*pdev,struct as3722_regulators *as3722_regs){
drivers/regulator/as3722-regulator.c +1
-1- pdev->dev.of_node = np; +platform_device_set_of_node (pdev, np);Are you sure this is safe to use during
probe(), which must of necessity happen afterplatform_device_add()? In particular with the interactions withfw_devlink.Signature · 1 line
Mark Brown <[email protected]>
Quoted 7 lines · Mark Brown
Quoted 6 lines
Use
platform_device_set_of_node()to synchronize both fields and give the device its own reference. Use__free(device_node)to releasestatic int as3722_get_regulator_dt_data(struct
platform_device*pdev,
structas3722_regulators*as3722_regs)
{
Quoted 7 lines
drivers/regulator/as3722-regulator.c line 599
Quoted 2 lines
drivers/regulator/as3722-regulator.c +1
-1- pdev->dev.of_node = np; +platform_device_set_of_node (pdev, np);Are you sure this is safe to use during
probe(), which must of necessity happen afterplatform_device_add()? In particular with the interactions withfw_devlink.
Good catch. I'm surprised sashiko didn't spot it.
Thanks,
Bartosz