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

leds: cr0014114: 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().

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

authored by

Javier Carrasco and committed by
Lee Jones
65135e2c a361af3c

+1 -3
+1 -3
drivers/leds/leds-cr0014114.c
··· 181 181 { 182 182 size_t i = 0; 183 183 struct cr0014114_led *led; 184 - struct fwnode_handle *child; 185 184 struct led_init_data init_data = {}; 186 185 int ret; 187 186 188 - device_for_each_child_node(priv->dev, child) { 187 + device_for_each_child_node_scoped(priv->dev, child) { 189 188 led = &priv->leds[i]; 190 189 191 190 led->priv = priv; ··· 200 201 if (ret) { 201 202 dev_err(priv->dev, 202 203 "failed to register LED device, err %d", ret); 203 - fwnode_handle_put(child); 204 204 return ret; 205 205 } 206 206