Skip to content

Commit 2e6980c

Browse files
javiercarrascocruzdtor
authored andcommitted
Input: mtk-pmic-keys - 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 ac2b6ce commit 2e6980c

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

drivers/input/keyboard/mtk-pmic-keys.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
307307
int error, index = 0;
308308
unsigned int keycount;
309309
struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent);
310-
struct device_node *node = pdev->dev.of_node, *child;
310+
struct device_node *node = pdev->dev.of_node;
311311
static const char *const irqnames[] = { "powerkey", "homekey" };
312312
static const char *const irqnames_r[] = { "powerkey_r", "homekey_r" };
313313
struct mtk_pmic_keys *keys;
@@ -343,24 +343,20 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
343343
return -EINVAL;
344344
}
345345

346-
for_each_child_of_node(node, child) {
346+
for_each_child_of_node_scoped(node, child) {
347347
keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
348348

349349
keys->keys[index].irq =
350350
platform_get_irq_byname(pdev, irqnames[index]);
351-
if (keys->keys[index].irq < 0) {
352-
of_node_put(child);
351+
if (keys->keys[index].irq < 0)
353352
return keys->keys[index].irq;
354-
}
355353

356354
if (of_device_is_compatible(node, "mediatek,mt6358-keys")) {
357355
keys->keys[index].irq_r = platform_get_irq_byname(pdev,
358356
irqnames_r[index]);
359357

360-
if (keys->keys[index].irq_r < 0) {
361-
of_node_put(child);
358+
if (keys->keys[index].irq_r < 0)
362359
return keys->keys[index].irq_r;
363-
}
364360
}
365361

366362
error = of_property_read_u32(child,
@@ -369,18 +365,15 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
369365
dev_err(keys->dev,
370366
"failed to read key:%d linux,keycode property: %d\n",
371367
index, error);
372-
of_node_put(child);
373368
return error;
374369
}
375370

376371
if (of_property_read_bool(child, "wakeup-source"))
377372
keys->keys[index].wakeup = true;
378373

379374
error = mtk_pmic_key_setup(keys, &keys->keys[index]);
380-
if (error) {
381-
of_node_put(child);
375+
if (error)
382376
return error;
383-
}
384377

385378
index++;
386379
}

0 commit comments

Comments
 (0)