mtd: hyperbus: rpc-if: fix an OF node reference leak
Subsystems (2)
PATCH v2 1/1 mtd: hyperbus: rpc-if: fix an OF node reference leak
rpcif_hb_probe() gets a child-node reference with of_get_next_child(). The HyperBus core does not consume it, so the driver leaks the reference on registration failure and remove.
Put the node on registration failure and after unregistering the HyperBus device on remove. Leave hardware initialization failures on out_disable_rpm, since no node reference has been acquired there.
---
Changes in v2:
- Move of_node_put() before pm_runtime_disable() in the remove path to match the probe error path, as suggested by Miquel Raynal.
v1: https://patchwork.ozlabs.org/project/linux-mtd/patch/[email protected]/
Based on linux-next next-20261016 (2efb7a11f1aa).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_OF_DYNAMIC=y. CONFIG_COMPILE_TEST=y.
The object was rebuilt from this exact base with v2 applied. No full kernel or module-link, hardware or runtime test was performed.
drivers/mtd/hyperbus/rpc-if.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/hyperbus/rpc-if.c +4 -1
@@ -145,10 +145,12 @@ static int rpcif_hb_probe(struct platform_device *pdev) hyperbus->hbdev.np =of_get_next_child (pdev->dev.parent->of_node,NULL ); error =hyperbus_register_device (&hyperbus->hbdev);if (error) - goto out_disable_rpm; + goto out_put_node;return 0 ; +out_put_node: +of_node_put (hyperbus->hbdev.np); out_disable_rpm:pm_runtime_disable (hyperbus->rpc.dev);return error;
@@ -159,6 +161,7 @@ static void rpcif_hb_remove(struct platform_device *pdev)struct rpcif_hyperbus *hyperbus =platform_get_drvdata (pdev);hyperbus_unregister_device (&hyperbus->hbdev); +of_node_put (hyperbus->hbdev.np);pm_runtime_disable (hyperbus->rpc.dev); }
base-commit: 2efb7a11f1aa4d2dc285fe2680cca22cb9f72f64
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 9 lines · Yige Jiang
rpcif_hb_probe()gets a child-node reference withof_get_next_child(). The HyperBus core does not consume it, so the driver leaks the reference on registration failure and remove.Put the node on registration failure and after unregistering the HyperBus device on remove. Leave hardware initialization failures on
out_disable_rpm, since no node reference has been acquired there.[...]
Applied to mtd/next, thanks!
[1/1] mtd: hyperbus: rpc-if: fix an OF node reference leak
commit: c16be34e0c713ddb8824c5f2ce9e3c4a3577dfac
Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl