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

leds: lm3697: Switch to device_for_each_child_node_scoped()

Switch to device_for_each_child_node_scoped() to simplify the code by
removing the need for calls to fwnode_handle_put() in the error paths.

This also prevents possible memory leaks if new error paths are added
without the required call to fwnode_handle_put().

After switching to the scoped variant, there is no longer need for a
jump to 'child_out', as an immediate return is possible.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-9-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Javier Carrasco and committed by
Lee Jones
6e2d1d83 7bd4b927

+6 -12
+6 -12
drivers/leds/leds-lm3697.c
··· 202 202 203 203 static int lm3697_probe_dt(struct lm3697 *priv) 204 204 { 205 - struct fwnode_handle *child = NULL; 206 205 struct device *dev = priv->dev; 207 206 struct lm3697_led *led; 208 207 int ret = -EINVAL; ··· 219 220 if (IS_ERR(priv->regulator)) 220 221 priv->regulator = NULL; 221 222 222 - device_for_each_child_node(dev, child) { 223 + device_for_each_child_node_scoped(dev, child) { 223 224 struct led_init_data init_data = {}; 224 225 225 226 ret = fwnode_property_read_u32(child, "reg", &control_bank); 226 227 if (ret) { 227 228 dev_err(dev, "reg property missing\n"); 228 - goto child_out; 229 + return ret; 229 230 } 230 231 231 232 if (control_bank > LM3697_CONTROL_B) { 232 233 dev_err(dev, "reg property is invalid\n"); 233 - ret = -EINVAL; 234 - goto child_out; 234 + return -EINVAL; 235 235 } 236 236 237 237 led = &priv->leds[i]; ··· 260 262 led->num_leds); 261 263 if (ret) { 262 264 dev_err(dev, "led-sources property missing\n"); 263 - goto child_out; 265 + return ret; 264 266 } 265 267 266 268 for (j = 0; j < led->num_leds; j++) ··· 284 286 &init_data); 285 287 if (ret) { 286 288 dev_err(dev, "led register err: %d\n", ret); 287 - goto child_out; 289 + return ret; 288 290 } 289 291 290 292 i++; 291 293 } 292 294 293 - return ret; 294 - 295 - child_out: 296 - fwnode_handle_put(child); 297 - return ret; 295 + return 0; 298 296 } 299 297 300 298 static int lm3697_probe(struct i2c_client *client)