diff mbox series

[2/2] leds: max5970: use cleanup facility for fwnode_handle led_node

Message ID 20241019-max5970-of_node_put-v1-2-e6ce4af4119b@gmail.com
State New
Headers show
Series leds: max5970: fix unreleased fwnode_handle in probe function | expand

Commit Message

Javier Carrasco Oct. 19, 2024, 7:36 p.m. UTC
Add the automatic cleanup facility for 'led_node' to simplify the code
and make it more robust against new error paths where omitting a call to
fwnode_handle_put() would leak memory.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/leds/leds-max5970.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Lee Jones Oct. 31, 2024, 4:14 p.m. UTC | #1
On Sat, 19 Oct 2024, Javier Carrasco wrote:

> Add the automatic cleanup facility for 'led_node' to simplify the code
> and make it more robust against new error paths where omitting a call to
> fwnode_handle_put() would leak memory.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
>  drivers/leds/leds-max5970.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)

This makes patch 1 completely pointless.

Please squash them and resubmit.
diff mbox series

Patch

diff --git a/drivers/leds/leds-max5970.c b/drivers/leds/leds-max5970.c
index c021330e0ae7..285074c53b23 100644
--- a/drivers/leds/leds-max5970.c
+++ b/drivers/leds/leds-max5970.c
@@ -45,7 +45,7 @@  static int max5970_led_set_brightness(struct led_classdev *cdev,
 
 static int max5970_led_probe(struct platform_device *pdev)
 {
-	struct fwnode_handle *led_node, *child;
+	struct fwnode_handle *child;
 	struct device *dev = &pdev->dev;
 	struct regmap *regmap;
 	struct max5970_led *ddata;
@@ -55,7 +55,8 @@  static int max5970_led_probe(struct platform_device *pdev)
 	if (!regmap)
 		return -ENODEV;
 
-	led_node = device_get_named_child_node(dev->parent, "leds");
+	struct fwnode_handle *led_node __free(fwnode_handle) =
+		device_get_named_child_node(dev->parent, "leds");
 	if (!led_node)
 		return -ENODEV;
 
@@ -72,7 +73,6 @@  static int max5970_led_probe(struct platform_device *pdev)
 
 		ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
 		if (!ddata) {
-			fwnode_handle_put(led_node);
 			fwnode_handle_put(child);
 			return -ENOMEM;
 		}
@@ -90,14 +90,11 @@  static int max5970_led_probe(struct platform_device *pdev)
 
 		ret = devm_led_classdev_register(dev, &ddata->cdev);
 		if (ret < 0) {
-			fwnode_handle_put(led_node);
 			fwnode_handle_put(child);
 			return dev_err_probe(dev, ret, "Failed to initialize LED %u\n", reg);
 		}
 	}
 
-	fwnode_handle_put(led_node);
-
 	return ret;
 }