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

leds: pca963x: 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 'err', 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-13-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Javier Carrasco and committed by
Lee Jones
dea90acb 5b5d936d

+3 -8
+3 -8
drivers/leds/leds-pca963x.c
··· 306 306 struct pca963x_chipdef *chipdef = chip->chipdef; 307 307 struct pca963x_led *led = chip->leds; 308 308 struct device *dev = &client->dev; 309 - struct fwnode_handle *child; 310 309 bool hw_blink; 311 310 s32 mode2; 312 311 u32 reg; ··· 337 338 if (ret < 0) 338 339 return ret; 339 340 340 - device_for_each_child_node(dev, child) { 341 + device_for_each_child_node_scoped(dev, child) { 341 342 struct led_init_data init_data = {}; 342 343 char default_label[32]; 343 344 ··· 345 346 if (ret || reg >= chipdef->n_leds) { 346 347 dev_err(dev, "Invalid 'reg' property for node %pfw\n", 347 348 child); 348 - ret = -EINVAL; 349 - goto err; 349 + return -EINVAL; 350 350 } 351 351 352 352 led->led_num = reg; ··· 367 369 if (ret) { 368 370 dev_err(dev, "Failed to register LED for node %pfw\n", 369 371 child); 370 - goto err; 372 + return ret; 371 373 } 372 374 373 375 ++led; 374 376 } 375 377 376 378 return 0; 377 - err: 378 - fwnode_handle_put(child); 379 - return ret; 380 379 } 381 380 382 381 static int pca963x_suspend(struct device *dev)