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

regulator: max8997: 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-3-87151088b883@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
ea13bd39 f372c262

+5 -6
+5 -6
drivers/regulator/max8997-regulator.c
··· 8 8 // This driver is based on max8998.c 9 9 10 10 #include <linux/bug.h> 11 + #include <linux/cleanup.h> 11 12 #include <linux/err.h> 12 13 #include <linux/gpio/consumer.h> 13 14 #include <linux/slab.h> ··· 877 876 struct max8997_platform_data *pdata) 878 877 { 879 878 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); 880 - struct device_node *pmic_np, *regulators_np, *reg_np; 879 + struct device_node *pmic_np, *reg_np; 881 880 struct max8997_regulator_data *rdata; 882 881 unsigned int i, dvs_voltage_nr = 1; 883 882 ··· 887 886 return -ENODEV; 888 887 } 889 888 890 - regulators_np = of_get_child_by_name(pmic_np, "regulators"); 889 + struct device_node *regulators_np __free(device_node) = of_get_child_by_name(pmic_np, 890 + "regulators"); 891 891 if (!regulators_np) { 892 892 dev_err(&pdev->dev, "could not find regulators sub-node\n"); 893 893 return -EINVAL; ··· 900 898 rdata = devm_kcalloc(&pdev->dev, 901 899 pdata->num_regulators, sizeof(*rdata), 902 900 GFP_KERNEL); 903 - if (!rdata) { 904 - of_node_put(regulators_np); 901 + if (!rdata) 905 902 return -ENOMEM; 906 - } 907 903 908 904 pdata->regulators = rdata; 909 905 for_each_child_of_node(regulators_np, reg_np) { ··· 922 922 rdata->reg_node = reg_np; 923 923 rdata++; 924 924 } 925 - of_node_put(regulators_np); 926 925 927 926 pdata->buck1_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck1-uses-gpio-dvs"); 928 927 pdata->buck2_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck2-uses-gpio-dvs");