Commit 10cc4876 authored by Javier Carrasco's avatar Javier Carrasco Committed by Lee Jones

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: default avatarJavier Carrasco <javier.carrasco.cruz@gmail.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20240721-device_for_each_child_node-available-v2-4-f33748fd8b2d@gmail.comSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent ffbf1fcb
...@@ -392,7 +392,7 @@ static int is31fl319x_parse_child_fw(const struct device *dev, ...@@ -392,7 +392,7 @@ static int is31fl319x_parse_child_fw(const struct device *dev,
static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
{ {
struct fwnode_handle *fwnode = dev_fwnode(dev), *child; struct fwnode_handle *fwnode = dev_fwnode(dev);
int count; int count;
int ret; int ret;
...@@ -404,7 +404,7 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) ...@@ -404,7 +404,7 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
is31->cdef = device_get_match_data(dev); is31->cdef = device_get_match_data(dev);
count = 0; count = 0;
fwnode_for_each_available_child_node(fwnode, child) device_for_each_child_node_scoped(dev, child)
count++; count++;
dev_dbg(dev, "probing with %d leds defined in DT\n", count); 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) ...@@ -414,33 +414,25 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
"Number of leds defined must be between 1 and %u\n", "Number of leds defined must be between 1 and %u\n",
is31->cdef->num_leds); is31->cdef->num_leds);
fwnode_for_each_available_child_node(fwnode, child) { device_for_each_child_node_scoped(dev, child) {
struct is31fl319x_led *led; struct is31fl319x_led *led;
u32 reg; u32 reg;
ret = fwnode_property_read_u32(child, "reg", &reg); ret = fwnode_property_read_u32(child, "reg", &reg);
if (ret) { if (ret)
ret = dev_err_probe(dev, ret, "Failed to read led 'reg' property\n"); return dev_err_probe(dev, ret, "Failed to read led 'reg' property\n");
goto put_child_node;
}
if (reg < 1 || reg > is31->cdef->num_leds) { if (reg < 1 || reg > is31->cdef->num_leds)
ret = dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg); return dev_err_probe(dev, -EINVAL, "invalid led reg %u\n", reg);
goto put_child_node;
}
led = &is31->leds[reg - 1]; led = &is31->leds[reg - 1];
if (led->configured) { if (led->configured)
ret = dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg); return dev_err_probe(dev, -EINVAL, "led %u is already configured\n", reg);
goto put_child_node;
}
ret = is31fl319x_parse_child_fw(dev, child, led, is31); ret = is31fl319x_parse_child_fw(dev, child, led, is31);
if (ret) { if (ret)
ret = dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg); return dev_err_probe(dev, ret, "led %u DT parsing failed\n", reg);
goto put_child_node;
}
led->configured = true; led->configured = true;
} }
...@@ -454,10 +446,6 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31) ...@@ -454,10 +446,6 @@ static int is31fl319x_parse_fw(struct device *dev, struct is31fl319x_chip *is31)
} }
return 0; return 0;
put_child_node:
fwnode_handle_put(child);
return ret;
} }
static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp) static inline int is31fl3190_microamp_to_cs(struct device *dev, u32 microamp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment