Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20241010-input_automate_of_node_put-v1-2-ebc62138fbf8@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Javier Carrasco and committed by
Dmitry Torokhov
2e6980c1 ac2b6ce6

+5 -12
+5 -12
drivers/input/keyboard/mtk-pmic-keys.c
··· 307 307 int error, index = 0; 308 308 unsigned int keycount; 309 309 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; 311 311 static const char *const irqnames[] = { "powerkey", "homekey" }; 312 312 static const char *const irqnames_r[] = { "powerkey_r", "homekey_r" }; 313 313 struct mtk_pmic_keys *keys; ··· 343 343 return -EINVAL; 344 344 } 345 345 346 - for_each_child_of_node(node, child) { 346 + for_each_child_of_node_scoped(node, child) { 347 347 keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index]; 348 348 349 349 keys->keys[index].irq = 350 350 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) 353 352 return keys->keys[index].irq; 354 - } 355 353 356 354 if (of_device_is_compatible(node, "mediatek,mt6358-keys")) { 357 355 keys->keys[index].irq_r = platform_get_irq_byname(pdev, 358 356 irqnames_r[index]); 359 357 360 - if (keys->keys[index].irq_r < 0) { 361 - of_node_put(child); 358 + if (keys->keys[index].irq_r < 0) 362 359 return keys->keys[index].irq_r; 363 - } 364 360 } 365 361 366 362 error = of_property_read_u32(child, ··· 365 369 dev_err(keys->dev, 366 370 "failed to read key:%d linux,keycode property: %d\n", 367 371 index, error); 368 - of_node_put(child); 369 372 return error; 370 373 } 371 374 ··· 372 377 keys->keys[index].wakeup = true; 373 378 374 379 error = mtk_pmic_key_setup(keys, &keys->keys[index]); 375 - if (error) { 376 - of_node_put(child); 380 + if (error) 377 381 return error; 378 - } 379 382 380 383 index++; 381 384 }