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

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

Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.

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

authored by

Krzysztof Kozlowski and committed by
Mark Brown
34a3f959 ea13bd39

+6 -11
+6 -11
drivers/regulator/s5m8767.c
··· 3 3 // Copyright (c) 2011 Samsung Electronics Co., Ltd 4 4 // http://www.samsung.com 5 5 6 + #include <linux/cleanup.h> 6 7 #include <linux/err.h> 7 8 #include <linux/of_gpio.h> 8 9 #include <linux/gpio/consumer.h> ··· 522 521 struct sec_platform_data *pdata) 523 522 { 524 523 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 525 - struct device_node *pmic_np, *regulators_np, *reg_np; 524 + struct device_node *pmic_np, *reg_np; 526 525 struct sec_regulator_data *rdata; 527 526 struct sec_opmode_data *rmode; 528 527 unsigned int i, dvs_voltage_nr = 8, ret; ··· 533 532 return -ENODEV; 534 533 } 535 534 536 - regulators_np = of_get_child_by_name(pmic_np, "regulators"); 535 + struct device_node *regulators_np __free(device_node) = of_get_child_by_name(pmic_np, 536 + "regulators"); 537 537 if (!regulators_np) { 538 538 dev_err(iodev->dev, "could not find regulators sub-node\n"); 539 539 return -EINVAL; ··· 546 544 rdata = devm_kcalloc(&pdev->dev, 547 545 pdata->num_regulators, sizeof(*rdata), 548 546 GFP_KERNEL); 549 - if (!rdata) { 550 - of_node_put(regulators_np); 547 + if (!rdata) 551 548 return -ENOMEM; 552 - } 553 549 554 550 rmode = devm_kcalloc(&pdev->dev, 555 551 pdata->num_regulators, sizeof(*rmode), 556 552 GFP_KERNEL); 557 - if (!rmode) { 558 - of_node_put(regulators_np); 553 + if (!rmode) 559 554 return -ENOMEM; 560 - } 561 555 562 556 pdata->regulators = rdata; 563 557 pdata->opmode = rmode; ··· 579 581 rdata->ext_control_gpiod = NULL; 580 582 } else if (IS_ERR(rdata->ext_control_gpiod)) { 581 583 of_node_put(reg_np); 582 - of_node_put(regulators_np); 583 584 return PTR_ERR(rdata->ext_control_gpiod); 584 585 } 585 586 ··· 599 602 } 600 603 rmode++; 601 604 } 602 - 603 - of_node_put(regulators_np); 604 605 605 606 if (of_property_read_bool(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs")) { 606 607 pdata->buck2_gpiodvs = true;