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

Input: cap11xx - 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-1-ebc62138fbf8@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Javier Carrasco and committed by
Dmitry Torokhov
ac2b6ce6 27216749

+4 -8
+4 -8
drivers/input/keyboard/cap11xx.c
··· 416 416 static int cap11xx_init_leds(struct device *dev, 417 417 struct cap11xx_priv *priv, int num_leds) 418 418 { 419 - struct device_node *node = dev->of_node, *child; 419 + struct device_node *node = dev->of_node; 420 420 struct cap11xx_led *led; 421 421 int cnt = of_get_child_count(node); 422 422 int error; ··· 445 445 if (error) 446 446 return error; 447 447 448 - for_each_child_of_node(node, child) { 448 + for_each_child_of_node_scoped(node, child) { 449 449 u32 reg; 450 450 451 451 led->cdev.name = ··· 458 458 led->cdev.brightness = LED_OFF; 459 459 460 460 error = of_property_read_u32(child, "reg", &reg); 461 - if (error != 0 || reg >= num_leds) { 462 - of_node_put(child); 461 + if (error != 0 || reg >= num_leds) 463 462 return -EINVAL; 464 - } 465 463 466 464 led->reg = reg; 467 465 led->priv = priv; 468 466 469 467 error = devm_led_classdev_register(dev, &led->cdev); 470 - if (error) { 471 - of_node_put(child); 468 + if (error) 472 469 return error; 473 - } 474 470 475 471 priv->num_leds++; 476 472 led++;