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

Javier Carrasco posted 2 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 2/2] leds: max5970: use cleanup facility for fwnode_handle led_node
Posted by Javier Carrasco 1 month, 1 week ago
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(-)

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;
 }
 

-- 
2.43.0
Re: [PATCH 2/2] leds: max5970: use cleanup facility for fwnode_handle led_node
Posted by Lee Jones 3 weeks, 4 days ago
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.

-- 
Lee Jones [李琼斯]