Skip to contentSkip to conversation

net: dsa: mv88e6xxx: Fix refcount leak in mv88e6xxx_mdios_register

PATCH Superseded Miaoqian Lin 2 participants 2 messages May 26, 2022

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: mv88e6xxx: Fix refcount leak in mv88e6xxx_mdios_register

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. This function missing of_node_put() in an error path. Add missing of_node_put() to avoid refcount leak.

---
 drivers/net/dsa/mv88e6xxx/chip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +3 -1
index 5d2c57a7c708..0726df6aeb1f 100644
@@ -3960,8 +3960,10 @@ static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
 	 */
 	child = of_get_child_by_name(np, "mdio");
 	err = mv88e6xxx_mdio_register(chip, child, false);
-	if (err)
+	if (err) {
+		of_node_put(child);
 		return err;
+	}
 
 	/* Walk the device tree, and see if there are any other nodes
 	 * which say they are compatible with the external mdio
Signature · 1 line
2.25.1
#1 lore raw
Quoted 16 lines · On Thu, 26 May 2022 12:37:48 +0400 Miaoqian Lin <[email protected]> wrote:

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when done. This function missing of_node_put() in an error path. Add missing of_node_put() to avoid refcount leak.

---
 drivers/net/dsa/mv88e6xxx/chip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +0 -0
index 5d2c57a7c708..0726df6aeb1f 100644
@@ -3960,8 +3960,10 @@ static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,
 	 */

drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip, · line 3969

Quoted 10 lines
drivers/net/dsa/mv88e6xxx/chip.c +3 -1
 	child = of_get_child_by_name(np, "mdio");
 	err = mv88e6xxx_mdio_register(chip, child, false);
-	if (err)
+	if (err) {
+		of_node_put(child);
 		return err;
+	}
 
 	/* Walk the device tree, and see if there are any other nodes
 	 * which say they are compatible with the external mdio

Fix needs Fixes tag so that it can be backported. Please add correct Fixes tag.