Skip to content

Commit 4ab3ae4

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: max77650: 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_node_out', as an immediate return is possible. Signed-off-by: Javier Carrasco <[email protected]> Acked-by: Bartosz Golaszewski <[email protected]> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-11-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent ba35b9a commit 4ab3ae4

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

drivers/leds/leds-max77650.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ static int max77650_led_brightness_set(struct led_classdev *cdev,
6262

6363
static int max77650_led_probe(struct platform_device *pdev)
6464
{
65-
struct fwnode_handle *child;
6665
struct max77650_led *leds, *led;
6766
struct device *dev;
6867
struct regmap *map;
@@ -84,14 +83,12 @@ static int max77650_led_probe(struct platform_device *pdev)
8483
if (!num_leds || num_leds > MAX77650_LED_NUM_LEDS)
8584
return -ENODEV;
8685

87-
device_for_each_child_node(dev, child) {
86+
device_for_each_child_node_scoped(dev, child) {
8887
struct led_init_data init_data = {};
8988

9089
rv = fwnode_property_read_u32(child, "reg", &reg);
91-
if (rv || reg >= MAX77650_LED_NUM_LEDS) {
92-
rv = -EINVAL;
93-
goto err_node_put;
94-
}
90+
if (rv || reg >= MAX77650_LED_NUM_LEDS)
91+
return -EINVAL;
9592

9693
led = &leds[reg];
9794
led->map = map;
@@ -108,23 +105,20 @@ static int max77650_led_probe(struct platform_device *pdev)
108105
rv = devm_led_classdev_register_ext(dev, &led->cdev,
109106
&init_data);
110107
if (rv)
111-
goto err_node_put;
108+
return rv;
112109

113110
rv = regmap_write(map, led->regA, MAX77650_LED_A_DEFAULT);
114111
if (rv)
115-
goto err_node_put;
112+
return rv;
116113

117114
rv = regmap_write(map, led->regB, MAX77650_LED_B_DEFAULT);
118115
if (rv)
119-
goto err_node_put;
116+
return rv;
120117
}
121118

122119
return regmap_write(map,
123120
MAX77650_REG_CNFG_LED_TOP,
124121
MAX77650_LED_TOP_DEFAULT);
125-
err_node_put:
126-
fwnode_handle_put(child);
127-
return rv;
128122
}
129123

130124
static const struct of_device_id max77650_led_of_match[] = {

0 commit comments

Comments
 (0)