Skip to contentSkip to conversation

net: dsa: microchip: ksz_common: Fix refcount leak bug

PATCH Applied Liang He 3 participants 3 messages Jul 14, 2022 – Jul 16, 2022

Subsystems (4)
lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH v2 1/1 net: dsa: microchip: ksz_common: Fix refcount leak bug

In ksz_switch_register(), we should call of_node_put() for the reference returned by of_get_child_by_name() which has increased the refcount.

Fixes 912aae27c6af ("net: dsa: microchip: really look for phy-mode in port nodes")

---
changelog:

v2: use correct fix tag advised by Vladimir Oltean
v1: fix bug

v1 link: https://lore.kernel.org/all/[email protected]/

 drivers/net/dsa/microchip/ksz_common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz_common.c +4 -1
index 9ca8c8d7740f..92a500e1ccd2 100644
@@ -1038,18 +1038,21 @@ int ksz_switch_register(struct ksz_device *dev,
 		ports = of_get_child_by_name(dev->dev->of_node, "ethernet-ports");
 		if (!ports)
 			ports = of_get_child_by_name(dev->dev->of_node, "ports");
-		if (ports)
+		if (ports) {
 			for_each_available_child_of_node(ports, port) {
 				if (of_property_read_u32(port, "reg",
 							 &port_num))
 					continue;
 				if (!(dev->port_mask & BIT(port_num))) {
 					of_node_put(port);
+					of_node_put(ports);
 					return -EINVAL;
 				}
 				of_get_phy_mode(port,
 						&dev->ports[port_num].interface);
 			}
+			of_node_put(ports);
+		}
 		dev->synclko_125 = of_property_read_bool(dev->dev->of_node,
 							 "microchip,synclko-125");
 		dev->synclko_disable = of_property_read_bool(dev->dev->of_node,
Signature · 1 line
2.25.1
#2 lore raw
In reply to Liang He
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 14 Jul 2022 23:31:38 +0800 you wrote:

In ksz_switch_register(), we should call of_node_put() for the reference returned by of_get_child_by_name() which has increased the refcount.

Fixes 912aae27c6af ("net: dsa: microchip: really look for phy-mode in port nodes")

[...]

Here is the summary with links:
- [v2] net: dsa: microchip: ksz_common: Fix refcount leak bug

    https://git.kernel.org/netdev/net/c/a14bd7475452

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html