Skip to content

Commit 10cc487

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: is31fl319x: Use device_for_each_child_node_scoped() to access child nodes
The iterated nodes are direct children of the device node, and the `device_for_each_child_node()` macro accounts for child node availability. `fwnode_for_each_available_child_node()` is meant to access the child nodes of an fwnode, and therefore not direct child nodes of the device node. In this case, the child nodes are not required outside the loop, and the scoped version of the macro can be used to remove the repetitive `goto put` pattern. Use `device_for_each_child_node_scoped_scoped()` to indicate device's direct child nodes. Signed-off-by: Javier Carrasco <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/20240721-device_for_each_child_node-available-v2-4-f33748fd8b2d@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent ffbf1fc commit 10cc487

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

drivers/leds/leds-is31fl319x.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static int is31fl319x_parse_child_fw(const struct device *dev,
392392

393393
static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
394394
{
395-
struct fwnode_handle *fwnode = dev_fwnode(dev), *child;
395+
struct fwnode_handle *fwnode = dev_fwnode(dev);
396396
int count;
397397
int ret;
398398

@@ -404,7 +404,7 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
404404
is31->cdef = device_get_match_data(dev);
405405

406406
count = 0;
407-
fwnode_for_each_available_child_node(fwnode, child)
407+
device_for_each_child_node_scoped(dev, child)
408408
count++;
409409

410410
dev_dbg(dev, "probing with %d leds defined in DT\n", count);
@@ -414,33 +414,25 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
414414
"Number of leds defined must be between 1 and %u\n",
415415
is31->cdef->num_leds);
416416

417-
fwnode_for_each_available_child_node(fwnode, child) {
417+
device_for_each_child_node_scoped(dev, child) {
418418
struct is31fl319x_led *led;
419419
u32 reg;
420420

421421
ret = fwnode_property_read_u32(child, "reg", &reg);
422-
if (ret) {
423-
ret = dev_err_probe(dev, ret, "Failed to read led 'reg' property\n");
424-
goto put_child_node;
425-
}
422+
if (ret)
423+
return dev_err_probe(dev, ret, "Failed to read led 'reg' property\n");
426424

427-
if (reg < 1 || reg > is31->cdef->num_leds) {
428-
ret = dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg);
429-
goto put_child_node;
430-
}
425+
if (reg < 1 || reg > is31->cdef->num_leds)
426+
return dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg);
431427

432428
led = &is31->leds[reg - 1];
433429

434-
if (led->configured) {
435-
ret = dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg);
436-
goto put_child_node;
437-
}
430+
if (led->configured)
431+
return dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg);
438432

439433
ret = is31fl319x_parse_child_fw(dev, child, led, is31);
440-
if (ret) {
441-
ret = dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg);
442-
goto put_child_node;
443-
}
434+
if (ret)
435+
return dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg);
444436

445437
led->configured = true;
446438
}
@@ -454,10 +446,6 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
454446
}
455447

456448
return 0;
457-
458-
put_child_node:
459-
fwnode_handle_put(child);
460-
return ret;
461449
}
462450

463451
static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp)

0 commit comments

Comments
 (0)