[PATCH net-next 2/3] net: dsa: mv88e6xxx: leds: fix led refcount in error path
From: Javier Carrasco
Date: Tue Oct 08 2024 - 12:11:25 EST
The 'led' fwnode_handle within fwnode_for_each_child_node() must be
released upon early exits by means of an explicit call to
fwnode_handle_put(), which in this case is missing.
Instead of adding the missing call, and considering that this driver was
recently introduced, use a scoped variant of the loop to automatically
decrement the child's refcount when it goes out of scope.
Note that the _avaialable_ version of the loop has been used, as there
is no apparent reason to walk over unavailable nodes.
Fixes: 94a2a84f5e9e ("net: dsa: mv88e6xxx: Support LED control")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx>
---
drivers/net/dsa/mv88e6xxx/leds.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/dsa/mv88e6xxx/leds.c b/drivers/net/dsa/mv88e6xxx/leds.c
index 1c88bfaea46b..92a57552beda 100644
--- a/drivers/net/dsa/mv88e6xxx/leds.c
+++ b/drivers/net/dsa/mv88e6xxx/leds.c
@@ -744,7 +744,7 @@ mv88e6xxx_led1_hw_control_get_device(struct led_classdev *ldev)
int mv88e6xxx_port_setup_leds(struct mv88e6xxx_chip *chip, int port)
{
- struct fwnode_handle *led = NULL, *leds = NULL;
+ struct fwnode_handle *leds = NULL;
struct led_init_data init_data = { };
enum led_default_state state;
struct mv88e6xxx_port *p;
@@ -770,7 +770,7 @@ int mv88e6xxx_port_setup_leds(struct mv88e6xxx_chip *chip, int port)
return 0;
}
- fwnode_for_each_child_node(leds, led) {
+ fwnode_for_each_available_child_node_scoped(leds, led) {
/* Reg represent the led number of the port, max 2
* LEDs can be connected to each port, in some designs
* only one LED is connected.
--
2.43.0