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

regulator: bd96801: Use scoped device node handling to simplify error paths

Obtain the device node reference with scoped/cleanup.h and use scoped
for_each_child_of_node_scoped() to reduce error handling and make the
code a bit simpler. Add also brackets {} over outer for loop for code
readability.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240814-cleanup-h-of-node-put-regulator-v1-2-87151088b883@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
f372c262 83c7cdee

+6 -11
+6 -11
drivers/regulator/bd96801-regulator.c
··· 34 34 * conflict in your downstream driver ;) 35 35 */ 36 36 37 + #include <linux/cleanup.h> 37 38 #include <linux/delay.h> 38 39 #include <linux/err.h> 39 40 #include <linux/interrupt.h> ··· 454 453 int num) 455 454 { 456 455 int i, ret; 457 - struct device_node *np; 458 - struct device_node *nproot = dev->parent->of_node; 459 456 460 - nproot = of_get_child_by_name(nproot, "regulators"); 457 + struct device_node *nproot __free(device_node) = 458 + of_get_child_by_name(dev->parent->of_node, "regulators"); 461 459 if (!nproot) { 462 460 dev_err(dev, "failed to find regulators node\n"); 463 461 return -ENODEV; 464 462 } 465 - for_each_child_of_node(nproot, np) 463 + for_each_child_of_node_scoped(nproot, np) { 466 464 for (i = 0; i < num; i++) { 467 465 if (!of_node_name_eq(np, data[i].desc.of_match)) 468 466 continue; ··· 476 476 dev_err(dev, 477 477 "Initializing voltages for %s failed\n", 478 478 data[i].desc.name); 479 - of_node_put(np); 480 - of_node_put(nproot); 481 - 482 479 return ret; 483 480 } 481 + 484 482 if (of_property_read_bool(np, "rohm,keep-on-stby")) { 485 483 ret = regmap_set_bits(regmap, 486 484 BD96801_ALWAYS_ON_REG, ··· 487 489 dev_err(dev, 488 490 "failed to set %s on-at-stby\n", 489 491 data[i].desc.name); 490 - of_node_put(np); 491 - of_node_put(nproot); 492 - 493 492 return ret; 494 493 } 495 494 } 496 495 } 497 - of_node_put(nproot); 496 + } 498 497 499 498 return 0; 500 499 }