Skip to content

Commit dea90ac

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

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/leds/leds-pca963x.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ static int pca963x_register_leds(struct i2c_client *client,
306306
struct pca963x_chipdef *chipdef = chip->chipdef;
307307
struct pca963x_led *led = chip->leds;
308308
struct device *dev = &client->dev;
309-
struct fwnode_handle *child;
310309
bool hw_blink;
311310
s32 mode2;
312311
u32 reg;
@@ -338,16 +337,15 @@ static int pca963x_register_leds(struct i2c_client *client,
338337
if (ret < 0)
339338
return ret;
340339

341-
device_for_each_child_node(dev, child) {
340+
device_for_each_child_node_scoped(dev, child) {
342341
struct led_init_data init_data = {};
343342
char default_label[32];
344343

345344
ret = fwnode_property_read_u32(child, "reg", &reg);
346345
if (ret || reg >= chipdef->n_leds) {
347346
dev_err(dev, "Invalid 'reg' property for node %pfw\n",
348347
child);
349-
ret = -EINVAL;
350-
goto err;
348+
return -EINVAL;
351349
}
352350

353351
led->led_num = reg;
@@ -369,16 +367,13 @@ static int pca963x_register_leds(struct i2c_client *client,
369367
if (ret) {
370368
dev_err(dev, "Failed to register LED for node %pfw\n",
371369
child);
372-
goto err;
370+
return ret;
373371
}
374372

375373
++led;
376374
}
377375

378376
return 0;
379-
err:
380-
fwnode_handle_put(child);
381-
return ret;
382377
}
383378

384379
static int pca963x_suspend(struct device *dev)

0 commit comments

Comments
 (0)