Skip to content

Commit 42b4967

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: gpio: 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 <[email protected]> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-7-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 9e445e2 commit 42b4967

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

drivers/leds/leds-gpio.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ struct gpio_leds_priv {
148148

149149
static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
150150
{
151-
struct fwnode_handle *child;
152151
struct gpio_leds_priv *priv;
153152
int count, used, ret;
154153

@@ -162,7 +161,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
162161
priv->num_leds = count;
163162
used = 0;
164163

165-
device_for_each_child_node(dev, child) {
164+
device_for_each_child_node_scoped(dev, child) {
166165
struct gpio_led_data *led_dat = &priv->leds[used];
167166
struct gpio_led led = {};
168167

@@ -176,7 +175,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
176175
if (IS_ERR(led.gpiod)) {
177176
dev_err_probe(dev, PTR_ERR(led.gpiod), "Failed to get GPIO '%pfw'\n",
178177
child);
179-
fwnode_handle_put(child);
180178
return ERR_CAST(led.gpiod);
181179
}
182180

@@ -192,10 +190,9 @@ static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
192190
led.panic_indicator = 1;
193191

194192
ret = create_gpio_led(&led, led_dat, dev, child, NULL);
195-
if (ret < 0) {
196-
fwnode_handle_put(child);
193+
if (ret < 0)
197194
return ERR_PTR(ret);
198-
}
195+
199196
/* Set gpiod label to match the corresponding LED name. */
200197
gpiod_set_consumer_name(led_dat->gpiod,
201198
led_dat->cdev.dev->kobj.name);

0 commit comments

Comments
 (0)