Skip to contentSkip to conversation

net dsa: qca8k: fix usages of device_get_named_child_node()

PATCH Superseded Andy Shevchenko 3 participants 3 messages Jun 4, 2024 – Jun 6, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net dsa: qca8k: fix usages of device_get_named_child_node()

The documentation for device_get_named_child_node() mentions this important point:

"
The caller is responsible for calling fwnode_handle_put() on the returned fwnode pointer.
"

Add fwnode_handle_put() to avoid leaked references.

Fixes 1e264f9d2918 ("net: dsa: qca8k: add LEDs basic support")
---
 drivers/net/dsa/qca/qca8k-leds.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/dsa/qca/qca8k-leds.c +9 -2
index 811ebeeff4ed..ef529615237c 100644
@@ -431,8 +431,10 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
 		init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d",
 						 priv->internal_mdio_bus->id,
 						 port_num);
-		if (!init_data.devicename)
+		if (!init_data.devicename) {
+			fwnode_handle_put(leds);
 			return -ENOMEM;
+		}
 
 		ret = devm_led_classdev_register_ext(priv->dev, &port_led->cdev, &init_data);
 		if (ret)
@@ -441,6 +443,7 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
 		kfree(init_data.devicename);
 	}
 
+	fwnode_handle_put(leds);
 	return 0;
 }
 
@@ -471,9 +474,13 @@ qca8k_setup_led_ctrl(struct qca8k_priv *priv)
 		 * the correct port for LED setup.
 		 */
 		ret = qca8k_parse_port_leds(priv, port, qca8k_port_to_phy(port_num));
-		if (ret)
+		if (ret) {
+			fwnode_handle_put(port);
+			fwnode_handle_put(ports);
 			return ret;
+		}
 	}
 
+	fwnode_handle_put(ports);
 	return 0;
 }
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andy Shevchenko

The documentation for device_get_named_child_node() mentions this important point:

"
The caller is responsible for calling fwnode_handle_put() on the returned fwnode pointer.
"

Quoted 4 lines

Add fwnode_handle_put() to avoid leaked references.

Fixes 1e264f9d2918 ("net: dsa: qca8k: add LEDs basic support")
maintainer
#2 lore raw
In reply to Andy Shevchenko

drivers/net/dsa/qca/qca8k-leds.c qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p · line 440

Quoted 12 lines · On Tue, 4 Jun 2024 19:15:51 +0300 Andy Shevchenko wrote:
drivers/net/dsa/qca/qca8k-leds.c +3 -1
@@ -431,8 +431,10 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
 		init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d",
 						 priv->internal_mdio_bus->id,
 						 port_num);
-		if (!init_data.devicename)
+		if (!init_data.devicename) {
+			fwnode_handle_put(leds);
 			return -ENOMEM;
+		}
 
 		ret = devm_led_classdev_register_ext(priv->dev, &port_led->cdev, &init_data);
 		if (ret)

I think there's more bugs in this here loop, if we break or return during fwnode_for_each_child_node() - we need to put the iterator (led).