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

leds: ns2: 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 path.

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

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-12-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Javier Carrasco and committed by
Lee Jones
5b5d936d 4ab3ae43

+2 -5
+2 -5
drivers/leds/leds-ns2.c
··· 238 238 static int ns2_led_probe(struct platform_device *pdev) 239 239 { 240 240 struct device *dev = &pdev->dev; 241 - struct fwnode_handle *child; 242 241 struct ns2_led *leds; 243 242 int count; 244 243 int ret; ··· 250 251 if (!leds) 251 252 return -ENOMEM; 252 253 253 - device_for_each_child_node(dev, child) { 254 + device_for_each_child_node_scoped(dev, child) { 254 255 ret = ns2_led_register(dev, child, leds++); 255 - if (ret) { 256 - fwnode_handle_put(child); 256 + if (ret) 257 257 return ret; 258 - } 259 258 } 260 259 261 260 return 0;