bus: vexpress-config: fix device_node refcount leak in vexpress_syscfg_probe()
PATCH 1/1 bus: vexpress-config: fix device_node refcount leak in vexpress_syscfg_probe()
vexpress_syscfg_probe() iterates the "arm,vexpress,config-bus" compatible nodes and, for each one, takes a reference to the bridge phandle via of_parse_phandle():
bridge_np = of_parse_phandle(node, "arm,vexpress,config-bridge", 0);
bridge_np is only compared against pdev->dev.parent->of_node and is never released - neither on the "continue" path when it does not match, nor on the path that calls of_platform_populate() and falls through to the next loop iteration. Each matching iteration leaks one device_node reference; the leak repeats on every probe (driver bind/unbind, module reload, or EPROBE_DEFER retry).
This is a regression of commit 557e37c05f28 ("bus: vexpress-config: add missing of_node_put after calling of_parse_phandle"), which fixed the equivalent leak in the predecessor function vexpress_config_populate(). Commit a5a38765ac79 ("bus: vexpress-config: simplify config bus probing") removed that function and inlined the loop into the probe routine, but did not carry over the of_node_put().
Use the __free(device_node) cleanup attribute on bridge_np so the reference is released automatically at the end of each loop iteration.
Found by static analysis tool CodeQL.
--- drivers/bus/vexpress-config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bus/vexpress-config.c +2 -2
@@ -390,9 +390,9 @@ static int vexpress_syscfg_probe(struct platform_device *pdev) }for_each_compatible_node (node,NULL ,"arm,vexpress,config-bus" ) { -struct device_node *bridge_np; + struct device_node *bridge_np __free(device_node) = +of_parse_phandle (node,"arm,vexpress,config-bridge" ,0 ); - bridge_np =of_parse_phandle (node,"arm,vexpress,config-bridge" ,0 );if (bridge_np != pdev->dev.parent->of_node)continue ;
base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193
Signature · 1 line
2.43.0
Quoted 20 lines · Weigang He
vexpress_syscfg_probe()iterates the "arm,vexpress,config-bus" compatible nodes and, for each one, takes a reference to the bridge phandle viaof_parse_phandle():bridge_np = of_parse_phandle(node, "arm,vexpress,config-bridge", 0);
bridge_npis only compared againstpdev->dev.parent->of_nodeand is never released - neither on the "continue" path when it does not match, nor on the path that callsof_platform_populate()and falls through to the next loop iteration. Each matching iteration leaks onedevice_nodereference; the leak repeats on every probe (driver bind/unbind, module reload, orEPROBE_DEFERretry).This is a regression of commit
557e37c05f28("bus: vexpress-config: add missingof_node_putafter callingof_parse_phandle"), which fixed the equivalent leak in the predecessor functionvexpress_config_populate(). Commita5a38765ac79("bus: vexpress-config: simplify config bus probing") removed that function and inlined the loop into the probe routine, but did not carry over theof_node_put().
Quoted 7 lines
Use the
__free(device_node)cleanup attribute onbridge_npso the reference is released automatically at the end of each loop iteration.Found by static analysis tool CodeQL.
Fixes a5a38765ac79 ("bus: vexpress-config: simplify config bus probing")Signed-off-by Weigang He <[email protected]>
Thanks for the fix!
Best regards,
Liviu
Quoted 25 lines
--- drivers/bus/vexpress-config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/bus/vexpress-config.c +2
-2@@ -390,9 +390,9 @@ static int vexpress_syscfg_probe(struct platform_device *pdev) }for_each_compatible_node (node,NULL ,"arm,vexpress,config-bus" ) { -struct device_node *bridge_np; + struct device_node *bridge_np __free(device_node) = +of_parse_phandle (node,"arm,vexpress,config-bridge" ,0 ); - bridge_np =of_parse_phandle (node,"arm,vexpress,config-bridge" ,0 );if (bridge_np != pdev->dev.parent->of_node)continue ;base-commit:
0f61b1860cc3f52aef9036d7235ed1f017632193Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯