regulator: Use scoped device node handling to simplify

Merge series from Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>:

Make code a bit smaller/simpler, with less of_node_put() thanks to
cleanup.h.
This commit is contained in:
Mark Brown
2024-08-15 14:35:02 +01:00
7 changed files with 32 additions and 62 deletions
+6 -13
View File
@@ -2,6 +2,7 @@
// Copyright (C) 2018 ROHM Semiconductors
// bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/interrupt.h>
@@ -1635,18 +1636,17 @@ static int get_special_regulators(struct device *dev,
unsigned int num_reg_data, int *info)
{
int ret;
struct device_node *np;
struct device_node *nproot = dev->of_node;
int uv;
*info = 0;
nproot = of_get_child_by_name(nproot, "regulators");
struct device_node *nproot __free(device_node) = of_get_child_by_name(dev->of_node,
"regulators");
if (!nproot) {
dev_err(dev, "failed to find regulators node\n");
return -ENODEV;
}
for_each_child_of_node(nproot, np) {
for_each_child_of_node_scoped(nproot, np) {
if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
mark_hw_controlled(dev, np, reg_data, num_reg_data,
info);
@@ -1656,22 +1656,15 @@ static int get_special_regulators(struct device *dev,
if (ret == -EINVAL)
continue;
else
goto err_out;
return ret;
}
ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
if (ret)
goto err_out;
return ret;
}
of_node_put(nproot);
return 0;
err_out:
of_node_put(np);
of_node_put(nproot);
return ret;
}
static int bd718xx_probe(struct platform_device *pdev)
+6 -11
View File
@@ -34,6 +34,7 @@
* conflict in your downstream driver ;)
*/
#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/interrupt.h>
@@ -453,15 +454,14 @@ static int bd96801_walk_regulator_dt(struct device *dev, struct regmap *regmap,
int num)
{
int i, ret;
struct device_node *np;
struct device_node *nproot = dev->parent->of_node;
nproot = of_get_child_by_name(nproot, "regulators");
struct device_node *nproot __free(device_node) =
of_get_child_by_name(dev->parent->of_node, "regulators");
if (!nproot) {
dev_err(dev, "failed to find regulators node\n");
return -ENODEV;
}
for_each_child_of_node(nproot, np)
for_each_child_of_node_scoped(nproot, np) {
for (i = 0; i < num; i++) {
if (!of_node_name_eq(np, data[i].desc.of_match))
continue;
@@ -476,11 +476,9 @@ static int bd96801_walk_regulator_dt(struct device *dev, struct regmap *regmap,
dev_err(dev,
"Initializing voltages for %s failed\n",
data[i].desc.name);
of_node_put(np);
of_node_put(nproot);
return ret;
}
if (of_property_read_bool(np, "rohm,keep-on-stby")) {
ret = regmap_set_bits(regmap,
BD96801_ALWAYS_ON_REG,
@@ -489,14 +487,11 @@ static int bd96801_walk_regulator_dt(struct device *dev, struct regmap *regmap,
dev_err(dev,
"failed to set %s on-at-stby\n",
data[i].desc.name);
of_node_put(np);
of_node_put(nproot);
return ret;
}
}
}
of_node_put(nproot);
}
return 0;
}
+5 -6
View File
@@ -8,6 +8,7 @@
// This driver is based on max8998.c
#include <linux/bug.h>
#include <linux/cleanup.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/slab.h>
@@ -876,7 +877,7 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
struct max8997_platform_data *pdata)
{
struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
struct device_node *pmic_np, *regulators_np, *reg_np;
struct device_node *pmic_np, *reg_np;
struct max8997_regulator_data *rdata;
unsigned int i, dvs_voltage_nr = 1;
@@ -886,7 +887,8 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
return -ENODEV;
}
regulators_np = of_get_child_by_name(pmic_np, "regulators");
struct device_node *regulators_np __free(device_node) = of_get_child_by_name(pmic_np,
"regulators");
if (!regulators_np) {
dev_err(&pdev->dev, "could not find regulators sub-node\n");
return -EINVAL;
@@ -898,10 +900,8 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata = devm_kcalloc(&pdev->dev,
pdata->num_regulators, sizeof(*rdata),
GFP_KERNEL);
if (!rdata) {
of_node_put(regulators_np);
if (!rdata)
return -ENOMEM;
}
pdata->regulators = rdata;
for_each_child_of_node(regulators_np, reg_np) {
@@ -922,7 +922,6 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata->reg_node = reg_np;
rdata++;
}
of_node_put(regulators_np);
pdata->buck1_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck1-uses-gpio-dvs");
pdata->buck2_gpiodvs = of_property_read_bool(pmic_np, "max8997,pmic-buck2-uses-gpio-dvs");
+3 -8
View File
@@ -1537,7 +1537,6 @@ static int rpmh_regulator_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
const struct rpmh_vreg_init_data *vreg_data;
struct device_node *node;
struct rpmh_vreg *vreg;
const char *pmic_id;
int ret;
@@ -1552,19 +1551,15 @@ static int rpmh_regulator_probe(struct platform_device *pdev)
return ret;
}
for_each_available_child_of_node(dev->of_node, node) {
for_each_available_child_of_node_scoped(dev->of_node, node) {
vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
if (!vreg) {
of_node_put(node);
if (!vreg)
return -ENOMEM;
}
ret = rpmh_regulator_init_vreg(vreg, dev, node, pmic_id,
vreg_data);
if (ret < 0) {
of_node_put(node);
if (ret < 0)
return ret;
}
}
return 0;
+3 -8
View File
@@ -1435,7 +1435,6 @@ static int rpm_reg_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
const struct rpm_regulator_data *vreg_data;
struct device_node *node;
struct qcom_rpm_reg *vreg;
struct qcom_smd_rpm *rpm;
int ret;
@@ -1455,18 +1454,14 @@ static int rpm_reg_probe(struct platform_device *pdev)
if (!vreg_data)
return -ENODEV;
for_each_available_child_of_node(dev->of_node, node) {
for_each_available_child_of_node_scoped(dev->of_node, node) {
vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL);
if (!vreg) {
of_node_put(node);
if (!vreg)
return -ENOMEM;
}
ret = rpm_regulator_init_vreg(vreg, dev, node, vreg_data);
if (ret < 0) {
of_node_put(node);
if (ret < 0)
return ret;
}
}
return 0;
+6 -11
View File
@@ -3,6 +3,7 @@
// Copyright (c) 2011 Samsung Electronics Co., Ltd
// http://www.samsung.com
#include <linux/cleanup.h>
#include <linux/err.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
@@ -521,7 +522,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
struct sec_platform_data *pdata)
{
struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
struct device_node *pmic_np, *regulators_np, *reg_np;
struct device_node *pmic_np, *reg_np;
struct sec_regulator_data *rdata;
struct sec_opmode_data *rmode;
unsigned int i, dvs_voltage_nr = 8, ret;
@@ -532,7 +533,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
return -ENODEV;
}
regulators_np = of_get_child_by_name(pmic_np, "regulators");
struct device_node *regulators_np __free(device_node) = of_get_child_by_name(pmic_np,
"regulators");
if (!regulators_np) {
dev_err(iodev->dev, "could not find regulators sub-node\n");
return -EINVAL;
@@ -544,18 +546,14 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata = devm_kcalloc(&pdev->dev,
pdata->num_regulators, sizeof(*rdata),
GFP_KERNEL);
if (!rdata) {
of_node_put(regulators_np);
if (!rdata)
return -ENOMEM;
}
rmode = devm_kcalloc(&pdev->dev,
pdata->num_regulators, sizeof(*rmode),
GFP_KERNEL);
if (!rmode) {
of_node_put(regulators_np);
if (!rmode)
return -ENOMEM;
}
pdata->regulators = rdata;
pdata->opmode = rmode;
@@ -581,7 +579,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata->ext_control_gpiod = NULL;
} else if (IS_ERR(rdata->ext_control_gpiod)) {
of_node_put(reg_np);
of_node_put(regulators_np);
return PTR_ERR(rdata->ext_control_gpiod);
}
@@ -603,8 +600,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rmode++;
}
of_node_put(regulators_np);
if (of_property_read_bool(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs")) {
pdata->buck2_gpiodvs = true;
+3 -5
View File
@@ -297,7 +297,7 @@ static int process_scmi_regulator_of_node(struct scmi_device *sdev,
static int scmi_regulator_probe(struct scmi_device *sdev)
{
int d, ret, num_doms;
struct device_node *np, *child;
struct device_node *np;
const struct scmi_handle *handle = sdev->handle;
struct scmi_regulator_info *rinfo;
struct scmi_protocol_handle *ph;
@@ -341,13 +341,11 @@ static int scmi_regulator_probe(struct scmi_device *sdev)
*/
of_node_get(handle->dev->of_node);
np = of_find_node_by_name(handle->dev->of_node, "regulators");
for_each_child_of_node(np, child) {
for_each_child_of_node_scoped(np, child) {
ret = process_scmi_regulator_of_node(sdev, ph, child, rinfo);
/* abort on any mem issue */
if (ret == -ENOMEM) {
of_node_put(child);
if (ret == -ENOMEM)
return ret;
}
}
of_node_put(np);
/*