Skip to contentSkip to conversation

can: flexcan: Fix OF node reference leak in flexcan_setup_stop_mode_gpr()

PATCH In review Wentao Liang 2 participants 2 messages Sep 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: flexcan: Fix OF node reference leak in flexcan_setup_stop_mode_gpr()

of_find_node_by_phandle() takes a reference on the GPR node and the error path releases it through out_put_node. The success path returns before reaching that label, so the reference is leaked every time the stop mode is set up successfully, and the node can never be freed.

Release the node reference before returning.

Fixes 13dfb3fa4943 ("Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net")
---
 drivers/net/can/flexcan/flexcan-core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/can/flexcan/flexcan-core.c +1 -0
index f5d22c61503f..68699d674fc3 100644
@@ -1986,6 +1986,7 @@ static int flexcan_setup_stop_mode_gpr(struct platform_device *pdev)
 		"gpr %s req_gpr=0x02%x req_bit=%u\n",
 		gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit);
 
+	of_node_put(gpr_np);
 	return 0;
 
 out_put_node:
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Wentao Liang

of_find_node_by_phandle() takes a reference on the GPR node and the error path releases it through out_put_node. The success path returns before reaching that label, so the reference is leaked every time the stop mode is set up successfully, and the node can never be freed.

Release the node reference before returning.

Fixes 13dfb3fa4943 ("Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net")

A merge commit probably has not introduced this problem...

Marc

Quoted 22 lines
---
 drivers/net/can/flexcan/flexcan-core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/can/flexcan/flexcan-core.c +1 -1
index f5d22c61503f..68699d674fc3 100644
@@ -1986,6 +1986,7 @@ static int flexcan_setup_stop_mode_gpr(struct platform_device *pdev)
 		"gpr %s req_gpr=0x02%x req_bit=%u\n",
 		gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit);
 
+	of_node_put(gpr_np);
 	return 0;
 
 out_put_node:
--

2.34.1

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |