Skip to contentSkip to conversation

net: mvpp2: Fix refcount leak in mvpp2_use_acpi_compat_mode

PATCH In review Miaoqian Lin 4 participants 4 messages Aug 30, 2025 – Sep 2, 2025

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

PATCH 1/1 net: mvpp2: Fix refcount leak in mvpp2_use_acpi_compat_mode

The function calls fwnode_get_named_child_node()
to check for a "fixed-link" child.
It did not release the reference if present, causing a refcount leak.

Fixes dfce1bab8fdc ("net: mvpp2: enable using phylink with ACPI")
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +13 -3
index 8ebb985d2573..1faed2ec3f4f 100644
@@ -6801,12 +6801,22 @@ static void mvpp2_acpi_start(struct mvpp2_port *port)
  */
 static bool mvpp2_use_acpi_compat_mode(struct fwnode_handle *port_fwnode)
 {
+	struct fwnode_handle *fixed_link;
+
 	if (!is_acpi_node(port_fwnode))
 		return false;
 
-	return (!fwnode_property_present(port_fwnode, "phy-handle") &&
-		!fwnode_property_present(port_fwnode, "managed") &&
-		!fwnode_get_named_child_node(port_fwnode, "fixed-link"));
+	if (fwnode_property_present(port_fwnode, "phy-handle") ||
+	    fwnode_property_present(port_fwnode, "managed"))
+		return false;
+
+	fixed_link = fwnode_get_named_child_node(port_fwnode, "fixed-link");
+	if (fixed_link) {
+		fwnode_handle_put(fixed_link);
+		return false;
+	}
+
+	return true;
 }
 
 /* Ports initialization */
Signature · 1 line
2.35.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Miaoqian Lin

The function calls fwnode_get_named_child_node()
to check for a "fixed-link" child.
It did not release the reference if present, causing a refcount leak.

Fixes dfce1bab8fdc ("net: mvpp2: enable using phylink with ACPI")

Probably this should be targeted at the net tree, like this

Subject: [PATCH net] ...

But that notwithstanding, this looks good to me.

maintainer
#2 lore raw
In reply to Miaoqian Lin

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp2_acpi_start(struct mvpp2_port *port) · line 6813

Quoted 8 lines · On Sat, 30 Aug 2025 17:18:54 +0800 Miaoqian Lin wrote:
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +5 -3
-	return (!fwnode_property_present(port_fwnode, "phy-handle") &&
-		!fwnode_property_present(port_fwnode, "managed") &&
-		!fwnode_get_named_child_node(port_fwnode, "fixed-link"));
+	if (fwnode_property_present(port_fwnode, "phy-handle") ||
+	    fwnode_property_present(port_fwnode, "managed"))
+		return false;
+
+	fixed_link = fwnode_get_named_child_node(port_fwnode, "fixed-link");

Wouldn't it be easier to switch to fwnode_get_named_child_node_count() ?

Signature · 1 line
pw-bot: cr