2024-06-11 00:18:37

by Marilene A Garcia

[permalink] [raw]
Subject: [PATCH linux-next] leds: tlc591xx: Replace of_node_put to __free

Use __free() for device_node values, and thus drop calls to
of_node_put().

The variable attribute __free() adds a scope based cleanup to
the device node. The goal is to reduce memory management issues
in the kernel code.

The for_each_available_child_of_node() was replaced to the equivalent
for_each_available_child_of_node_scoped() which uses the __free().

Suggested-by: Julia Lawall <[email protected]>
Signed-off-by: Marilene A Garcia <[email protected]>
---
Hello,
These are the changes related to adding the new __free cleanup
in the tlc591xx led driver.

Thank you.

drivers/leds/leds-tlc591xx.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
index 945e831ef4ac..6605e08a042a 100644
--- a/drivers/leds/leds-tlc591xx.c
+++ b/drivers/leds/leds-tlc591xx.c
@@ -146,7 +146,7 @@ MODULE_DEVICE_TABLE(of, of_tlc591xx_leds_match);
static int
tlc591xx_probe(struct i2c_client *client)
{
- struct device_node *np, *child;
+ struct device_node *np;
struct device *dev = &client->dev;
const struct tlc591xx *tlc591xx;
struct tlc591xx_priv *priv;
@@ -182,22 +182,20 @@ tlc591xx_probe(struct i2c_client *client)
if (err < 0)
return err;

- for_each_available_child_of_node(np, child) {
+ for_each_available_child_of_node_scoped(np, child) {
struct tlc591xx_led *led;
struct led_init_data init_data = {};

init_data.fwnode = of_fwnode_handle(child);

err = of_property_read_u32(child, "reg", &reg);
- if (err) {
- of_node_put(child);
+ if (err)
return err;
- }
+
if (reg < 0 || reg >= tlc591xx->max_leds ||
- priv->leds[reg].active) {
- of_node_put(child);
+ priv->leds[reg].active)
return -EINVAL;
- }
+
led = &priv->leds[reg];

led->active = true;
@@ -207,12 +205,10 @@ tlc591xx_probe(struct i2c_client *client)
led->ldev.max_brightness = TLC591XX_MAX_BRIGHTNESS;
err = devm_led_classdev_register_ext(dev, &led->ldev,
&init_data);
- if (err < 0) {
- of_node_put(child);
+ if (err < 0)
return dev_err_probe(dev, err,
"couldn't register LED %s\n",
led->ldev.name);
- }
}
return 0;
}
--
2.34.1



2024-06-13 17:15:59

by Lee Jones

[permalink] [raw]
Subject: Re: (subset) [PATCH linux-next] leds: tlc591xx: Replace of_node_put to __free

On Mon, 10 Jun 2024 21:17:40 -0300, Marilene A Garcia wrote:
> Use __free() for device_node values, and thus drop calls to
> of_node_put().
>
> The variable attribute __free() adds a scope based cleanup to
> the device node. The goal is to reduce memory management issues
> in the kernel code.
>
> [...]

Applied, thanks!

[1/1] leds: tlc591xx: Replace of_node_put to __free
commit: 5e6bc823b5c152b2a7854c61ec2054b0223ad2dd

--
Lee Jones [李琼斯]