Skip to contentSkip to conversation

leds: lp50xx: use scoped loop to fix fwnode reference leak in lp50xx_probe_dt()

PATCH In review Manush Prajwal 4 participants 4 messages Oct 1 – Oct 15 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: lp50xx: use scoped loop to fix fwnode reference leak in lp50xx_probe_dt()

In lp50xx_probe_dt(), fwnode_for_each_child_node(child, led_node) iterates over each sub-LED child node. If fwnode_property_read_u32() for "reg" fails or if multi_index >= LP50XX_LEDS_PER_MODULE, the function returns -EINVAL without dropping the reference count of led_node, leaking the fwnode.

Use fwnode_for_each_child_node_scoped() to automatically release led_node on all exit paths, eliminating the refcount leak as well as the manual fwnode_handle_put(led_node) on the "color" property failure path, and remove the now unnecessary function-scope led_node variable declaration.

Fixes 193910c2c54e ("leds: lp50xx: Add the LP50XX family of the RGB LED driver")
---
 drivers/leds/leds-lp50xx.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/leds/leds-lp50xx.c +1 -3
index 20bfb315b..d542eedd4 100644
@@ -458,7 +458,6 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
 
 static int lp50xx_probe_dt(struct lp50xx *priv)
 {
-	struct fwnode_handle *led_node = NULL;
 	struct led_init_data init_data = {};
 	struct led_classdev *led_cdev;
 	struct mc_subled *mc_led_info;
@@ -505,12 +504,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 		if (!mc_led_info)
 			return -ENOMEM;
 
-		fwnode_for_each_child_node(child, led_node) {
+		fwnode_for_each_child_node_scoped(child, led_node) {
 			int multi_index;
 			ret = fwnode_property_read_u32(led_node, "color",
 						       &color_id);
 			if (ret) {
-				fwnode_handle_put(led_node);
 				dev_err(priv->dev, "Cannot read color\n");
 				return ret;
 			}
Signature · 1 line
2.46.2.windows.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] leds: commit message description is not capitalized --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] leds: commit message description is not capitalized
--

commit 0f74bc379bcec72de3189968214e524ff15885d0
Author: Manush Prajwal <[email protected]>

leds: lp50xx: use scoped loop to fix fwnode reference leak in lp50xx_probe_dt()

This commit fixes an fwnode reference leak in lp50xx_probe_dt() by using fwnode_for_each_child_node_scoped(). This automatically handles reference counting for the child node across all exit paths, eliminating the need for manual cleanup on failure.

Quoted 1 line

leds: lp50xx: use scoped loop to fix fwnode reference leak in lp50xx_probe_dt()

[Severity: Low]
This isn't a bug, but does the commit subject violate the subsystem's naming conventions? The LED subsystem guidelines require the description following the prefix to be capitalized (e.g., "leds: lp50xx: Use scoped loop...").

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Manush Prajwal
Quoted 32 lines · Manush Prajwal

In lp50xx_probe_dt(), fwnode_for_each_child_node(child, led_node) iterates over each sub-LED child node. If fwnode_property_read_u32() for "reg" fails or if multi_index >= LP50XX_LEDS_PER_MODULE, the function returns -EINVAL without dropping the reference count of led_node, leaking the fwnode.

Use fwnode_for_each_child_node_scoped() to automatically release led_node on all exit paths, eliminating the refcount leak as well as the manual fwnode_handle_put(led_node) on the "color" property failure path, and remove the now unnecessary function-scope led_node variable declaration.

Fixes 193910c2c54e ("leds: lp50xx: Add the LP50XX family of the RGB LED driver")
---
  drivers/leds/leds-lp50xx.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/leds/leds-lp50xx.c +0 -1
index 20bfb315b..d542eedd4 100644
@@ -458,7 +458,6 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
 
  static int lp50xx_probe_dt(struct lp50xx *priv)
  {
-	struct fwnode_handle *led_node = NULL;
  	struct led_init_data init_data = {};
  	struct led_classdev *led_cdev;
  	struct mc_subled *mc_led_info;
@@ -505,12 +504,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
  		if (!mc_led_info)
  			return -ENOMEM;
 

drivers/leds/leds-lp50xx.c static int lp50xx_probe_dt(struct lp50xx *priv) · line 514

Quoted 10 lines
drivers/leds/leds-lp50xx.c +1 -2
-		fwnode_for_each_child_node(child, led_node) {
+		fwnode_for_each_child_node_scoped(child, led_node) {
  			int multi_index;
  			ret = fwnode_property_read_u32(led_node, "color",
  						       &color_id);
  			if (ret) {
-				fwnode_handle_put(led_node);
  				dev_err(priv->dev, "Cannot read color\n");
  				return ret;
  			}
maintainer
#3 lore raw
In reply to Manush Prajwal
Quoted 11 lines · Manush Prajwal

In lp50xx_probe_dt(), fwnode_for_each_child_node(child, led_node) iterates over each sub-LED child node. If fwnode_property_read_u32() for "reg" fails or if multi_index >= LP50XX_LEDS_PER_MODULE, the function returns -EINVAL without dropping the reference count of led_node, leaking the fwnode.

Use fwnode_for_each_child_node_scoped() to automatically release led_node on all exit paths, eliminating the refcount leak as well as the manual fwnode_handle_put(led_node) on the "color" property failure path, and remove the now unnecessary function-scope led_node variable declaration.

Fixes 193910c2c54e ("leds: lp50xx: Add the LP50XX family of the RGB LED driver")

This doesn't appear to be a real commit.

Quoted 36 lines
---
 drivers/leds/leds-lp50xx.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/leds/leds-lp50xx.c +1 -3
index 20bfb315b..d542eedd4 100644
@@ -458,7 +458,6 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
 
 static int lp50xx_probe_dt(struct lp50xx *priv)
 {
-	struct fwnode_handle *led_node = NULL;
 	struct led_init_data init_data = {};
 	struct led_classdev *led_cdev;
 	struct mc_subled *mc_led_info;
@@ -505,12 +504,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 		if (!mc_led_info)
 			return -ENOMEM;
 
-		fwnode_for_each_child_node(child, led_node) {
+		fwnode_for_each_child_node_scoped(child, led_node) {
 			int multi_index;
 			ret = fwnode_property_read_u32(led_node, "color",
 						       &color_id);
 			if (ret) {
-				fwnode_handle_put(led_node);
 				dev_err(priv->dev, "Cannot read color\n");
 				return ret;
 			}
Signature · 1 line
2.46.2.windows.1
Signature · 1 line
Lee Jones