Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Marilene A Garcia and committed by
Lee Jones
8d89afc6 7e776e21

+7 -11
+7 -11
drivers/leds/leds-tlc591xx.c
··· 146 146 static int 147 147 tlc591xx_probe(struct i2c_client *client) 148 148 { 149 - struct device_node *np, *child; 149 + struct device_node *np; 150 150 struct device *dev = &client->dev; 151 151 const struct tlc591xx *tlc591xx; 152 152 struct tlc591xx_priv *priv; ··· 182 182 if (err < 0) 183 183 return err; 184 184 185 - for_each_available_child_of_node(np, child) { 185 + for_each_available_child_of_node_scoped(np, child) { 186 186 struct tlc591xx_led *led; 187 187 struct led_init_data init_data = {}; 188 188 189 189 init_data.fwnode = of_fwnode_handle(child); 190 190 191 191 err = of_property_read_u32(child, "reg", &reg); 192 - if (err) { 193 - of_node_put(child); 192 + if (err) 194 193 return err; 195 - } 194 + 196 195 if (reg < 0 || reg >= tlc591xx->max_leds || 197 - priv->leds[reg].active) { 198 - of_node_put(child); 196 + priv->leds[reg].active) 199 197 return -EINVAL; 200 - } 198 + 201 199 led = &priv->leds[reg]; 202 200 203 201 led->active = true; ··· 205 207 led->ldev.max_brightness = TLC591XX_MAX_BRIGHTNESS; 206 208 err = devm_led_classdev_register_ext(dev, &led->ldev, 207 209 &init_data); 208 - if (err < 0) { 209 - of_node_put(child); 210 + if (err < 0) 210 211 return dev_err_probe(dev, err, 211 212 "couldn't register LED %s\n", 212 213 led->ldev.name); 213 - } 214 214 } 215 215 return 0; 216 216 }