Skip to content

Commit 6e2d1d8

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

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

drivers/leds/leds-lm3697.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ static int lm3697_init(struct lm3697 *priv)
202202

203203
static int lm3697_probe_dt(struct lm3697 *priv)
204204
{
205-
struct fwnode_handle *child = NULL;
206205
struct device *dev = priv->dev;
207206
struct lm3697_led *led;
208207
int ret = -EINVAL;
@@ -220,19 +219,18 @@ static int lm3697_probe_dt(struct lm3697 *priv)
220219
if (IS_ERR(priv->regulator))
221220
priv->regulator = NULL;
222221

223-
device_for_each_child_node(dev, child) {
222+
device_for_each_child_node_scoped(dev, child) {
224223
struct led_init_data init_data = {};
225224

226225
ret = fwnode_property_read_u32(child, "reg", &control_bank);
227226
if (ret) {
228227
dev_err(dev, "reg property missing\n");
229-
goto child_out;
228+
return ret;
230229
}
231230

232231
if (control_bank > LM3697_CONTROL_B) {
233232
dev_err(dev, "reg property is invalid\n");
234-
ret = -EINVAL;
235-
goto child_out;
233+
return -EINVAL;
236234
}
237235

238236
led = &priv->leds[i];
@@ -262,7 +260,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)
262260
led->num_leds);
263261
if (ret) {
264262
dev_err(dev, "led-sources property missing\n");
265-
goto child_out;
263+
return ret;
266264
}
267265

268266
for (j = 0; j < led->num_leds; j++)
@@ -286,17 +284,13 @@ static int lm3697_probe_dt(struct lm3697 *priv)
286284
&init_data);
287285
if (ret) {
288286
dev_err(dev, "led register err: %d\n", ret);
289-
goto child_out;
287+
return ret;
290288
}
291289

292290
i++;
293291
}
294292

295-
return ret;
296-
297-
child_out:
298-
fwnode_handle_put(child);
299-
return ret;
293+
return 0;
300294
}
301295

302296
static int lm3697_probe(struct i2c_client *client)

0 commit comments

Comments
 (0)