mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 16:56:26 +00:00
leds: lm3697: 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 'child_out', as an immediate return is possible. Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-9-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
parent
7bd4b9277b
commit
6e2d1d83b7
@ -202,7 +202,6 @@ static int lm3697_init(struct lm3697 *priv)
|
||||
|
||||
static int lm3697_probe_dt(struct lm3697 *priv)
|
||||
{
|
||||
struct fwnode_handle *child = NULL;
|
||||
struct device *dev = priv->dev;
|
||||
struct lm3697_led *led;
|
||||
int ret = -EINVAL;
|
||||
@ -220,19 +219,18 @@ static int lm3697_probe_dt(struct lm3697 *priv)
|
||||
if (IS_ERR(priv->regulator))
|
||||
priv->regulator = NULL;
|
||||
|
||||
device_for_each_child_node(dev, child) {
|
||||
device_for_each_child_node_scoped(dev, child) {
|
||||
struct led_init_data init_data = {};
|
||||
|
||||
ret = fwnode_property_read_u32(child, "reg", &control_bank);
|
||||
if (ret) {
|
||||
dev_err(dev, "reg property missing\n");
|
||||
goto child_out;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (control_bank > LM3697_CONTROL_B) {
|
||||
dev_err(dev, "reg property is invalid\n");
|
||||
ret = -EINVAL;
|
||||
goto child_out;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
led = &priv->leds[i];
|
||||
@ -262,7 +260,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)
|
||||
led->num_leds);
|
||||
if (ret) {
|
||||
dev_err(dev, "led-sources property missing\n");
|
||||
goto child_out;
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (j = 0; j < led->num_leds; j++)
|
||||
@ -286,17 +284,13 @@ static int lm3697_probe_dt(struct lm3697 *priv)
|
||||
&init_data);
|
||||
if (ret) {
|
||||
dev_err(dev, "led register err: %d\n", ret);
|
||||
goto child_out;
|
||||
return ret;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
child_out:
|
||||
fwnode_handle_put(child);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lm3697_probe(struct i2c_client *client)
|
||||
|
Loading…
Reference in New Issue
Block a user