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 <julia.lawall@inria.fr>
Signed-off-by: Marilene A Garcia <marilene.agarcia@gmail.com>
Link: https://lore.kernel.org/r/20240611001740.10490-1-marilene.agarcia@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Marilene A Garcia 2024-06-10 21:17:40 -03:00 committed by Lee Jones
parent 7e776e2125
commit 8d89afc635

View File

@ -146,7 +146,7 @@ MODULE_DEVICE_TABLE(of, of_tlc591xx_leds_match);
static int static int
tlc591xx_probe(struct i2c_client *client) tlc591xx_probe(struct i2c_client *client)
{ {
struct device_node *np, *child; struct device_node *np;
struct device *dev = &client->dev; struct device *dev = &client->dev;
const struct tlc591xx *tlc591xx; const struct tlc591xx *tlc591xx;
struct tlc591xx_priv *priv; struct tlc591xx_priv *priv;
@ -182,22 +182,20 @@ tlc591xx_probe(struct i2c_client *client)
if (err < 0) if (err < 0)
return err; return err;
for_each_available_child_of_node(np, child) { for_each_available_child_of_node_scoped(np, child) {
struct tlc591xx_led *led; struct tlc591xx_led *led;
struct led_init_data init_data = {}; struct led_init_data init_data = {};
init_data.fwnode = of_fwnode_handle(child); init_data.fwnode = of_fwnode_handle(child);
err = of_property_read_u32(child, "reg", &reg); err = of_property_read_u32(child, "reg", &reg);
if (err) { if (err)
of_node_put(child);
return err; return err;
}
if (reg < 0 || reg >= tlc591xx->max_leds || if (reg < 0 || reg >= tlc591xx->max_leds ||
priv->leds[reg].active) { priv->leds[reg].active)
of_node_put(child);
return -EINVAL; return -EINVAL;
}
led = &priv->leds[reg]; led = &priv->leds[reg];
led->active = true; led->active = true;
@ -207,13 +205,11 @@ tlc591xx_probe(struct i2c_client *client)
led->ldev.max_brightness = TLC591XX_MAX_BRIGHTNESS; led->ldev.max_brightness = TLC591XX_MAX_BRIGHTNESS;
err = devm_led_classdev_register_ext(dev, &led->ldev, err = devm_led_classdev_register_ext(dev, &led->ldev,
&init_data); &init_data);
if (err < 0) { if (err < 0)
of_node_put(child);
return dev_err_probe(dev, err, return dev_err_probe(dev, err,
"couldn't register LED %s\n", "couldn't register LED %s\n",
led->ldev.name); led->ldev.name);
} }
}
return 0; return 0;
} }