[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241019-max5970-of_node_put-v1-2-e6ce4af4119b@gmail.com>
Date: Sat, 19 Oct 2024 21:36:44 +0200
From: Javier Carrasco <javier.carrasco.cruz@...il.com>
To: Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
Patrick Rudolph <patrick.rudolph@...ements.com>,
Naresh Solanki <Naresh.Solanki@...ements.com>
Cc: linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org,
Javier Carrasco <javier.carrasco.cruz@...il.com>
Subject: [PATCH 2/2] leds: max5970: use cleanup facility for fwnode_handle
led_node
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@...il.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
Powered by blists - more mailing lists