Skip to content

Commit ac2b6ce

Browse files
javiercarrascocruzdtor
authored andcommitted
Input: cap11xx - switch to for_each_child_of_node_scoped
Use the scoped variant of the macro to simplify the code and error handling. This makes the error handling more robust by ensuring that the child node is always freed. Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 2721674 commit ac2b6ce

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/input/keyboard/cap11xx.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static int cap11xx_led_set(struct led_classdev *cdev,
416416
static int cap11xx_init_leds(struct device *dev,
417417
struct cap11xx_priv *priv, int num_leds)
418418
{
419-
struct device_node *node = dev->of_node, *child;
419+
struct device_node *node = dev->of_node;
420420
struct cap11xx_led *led;
421421
int cnt = of_get_child_count(node);
422422
int error;
@@ -445,7 +445,7 @@ static int cap11xx_init_leds(struct device *dev,
445445
if (error)
446446
return error;
447447

448-
for_each_child_of_node(node, child) {
448+
for_each_child_of_node_scoped(node, child) {
449449
u32 reg;
450450

451451
led->cdev.name =
@@ -458,19 +458,15 @@ static int cap11xx_init_leds(struct device *dev,
458458
led->cdev.brightness = LED_OFF;
459459

460460
error = of_property_read_u32(child, "reg", &reg);
461-
if (error != 0 || reg >= num_leds) {
462-
of_node_put(child);
461+
if (error != 0 || reg >= num_leds)
463462
return -EINVAL;
464-
}
465463

466464
led->reg = reg;
467465
led->priv = priv;
468466

469467
error = devm_led_classdev_register(dev, &led->cdev);
470-
if (error) {
471-
of_node_put(child);
468+
if (error)
472469
return error;
473-
}
474470

475471
priv->num_leds++;
476472
led++;

0 commit comments

Comments
 (0)