Commit 34a3f959 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Mark Brown

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: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240814-cleanup-h-of-node-put-regulator-v1-4-87151088b883@linaro.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent ea13bd39
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// Copyright (c) 2011 Samsung Electronics Co., Ltd // Copyright (c) 2011 Samsung Electronics Co., Ltd
// http://www.samsung.com // http://www.samsung.com
#include <linux/cleanup.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
...@@ -521,7 +522,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, ...@@ -521,7 +522,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
struct sec_platform_data *pdata) struct sec_platform_data *pdata)
{ {
struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 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_regulator_data *rdata;
struct sec_opmode_data *rmode; struct sec_opmode_data *rmode;
unsigned int i, dvs_voltage_nr = 8, ret; unsigned int i, dvs_voltage_nr = 8, ret;
...@@ -532,7 +533,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, ...@@ -532,7 +533,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
return -ENODEV; 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) { if (!regulators_np) {
dev_err(iodev->dev, "could not find regulators sub-node\n"); dev_err(iodev->dev, "could not find regulators sub-node\n");
return -EINVAL; return -EINVAL;
...@@ -544,18 +546,14 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, ...@@ -544,18 +546,14 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata = devm_kcalloc(&pdev->dev, rdata = devm_kcalloc(&pdev->dev,
pdata->num_regulators, sizeof(*rdata), pdata->num_regulators, sizeof(*rdata),
GFP_KERNEL); GFP_KERNEL);
if (!rdata) { if (!rdata)
of_node_put(regulators_np);
return -ENOMEM; return -ENOMEM;
}
rmode = devm_kcalloc(&pdev->dev, rmode = devm_kcalloc(&pdev->dev,
pdata->num_regulators, sizeof(*rmode), pdata->num_regulators, sizeof(*rmode),
GFP_KERNEL); GFP_KERNEL);
if (!rmode) { if (!rmode)
of_node_put(regulators_np);
return -ENOMEM; return -ENOMEM;
}
pdata->regulators = rdata; pdata->regulators = rdata;
pdata->opmode = rmode; pdata->opmode = rmode;
...@@ -581,7 +579,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, ...@@ -581,7 +579,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata->ext_control_gpiod = NULL; rdata->ext_control_gpiod = NULL;
} else if (IS_ERR(rdata->ext_control_gpiod)) { } else if (IS_ERR(rdata->ext_control_gpiod)) {
of_node_put(reg_np); of_node_put(reg_np);
of_node_put(regulators_np);
return PTR_ERR(rdata->ext_control_gpiod); return PTR_ERR(rdata->ext_control_gpiod);
} }
...@@ -603,8 +600,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev, ...@@ -603,8 +600,6 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rmode++; rmode++;
} }
of_node_put(regulators_np);
if (of_property_read_bool(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs")) { if (of_property_read_bool(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs")) {
pdata->buck2_gpiodvs = true; pdata->buck2_gpiodvs = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment