diff mbox series

[net-next,2/3] net: dsa: mv88e6xxx: leds: fix led refcount in error path

Message ID 20241008-mv88e6xxx_leds_fwnode_put-v1-2-cfd7758cd176@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net, device property: fix led node releases in mv88e6xxx with new macro | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Javier Carrasco Oct. 8, 2024, 4:10 p.m. UTC
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@gmail.com>
---
 drivers/net/dsa/mv88e6xxx/leds.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Lunn Oct. 8, 2024, 4:38 p.m. UTC | #1
On Tue, Oct 08, 2024 at 06:10:28PM +0200, Javier Carrasco wrote:
> 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@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Andy Shevchenko Oct. 10, 2024, 2:30 p.m. UTC | #2
On Tue, Oct 08, 2024 at 06:10:28PM +0200, Javier Carrasco wrote:
> 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.

...

> -	struct fwnode_handle *led = NULL, *leds = NULL;
> +	struct fwnode_handle *leds = NULL;

Can it be const now?
diff mbox series

Patch

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.