public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths
@ 2024-08-14 15:04 Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 1/7] regulator: bd718x7: " Krzysztof Kozlowski
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

Hi,

Make code a bit smaller/simpler, with less of_node_put() thanks to
cleanup.h.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (7):
      regulator: bd718x7: Use scoped device node handling to simplify error paths
      regulator: bd96801: Use scoped device node handling to simplify error paths
      regulator: max8997: Use scoped device node handling to simplify error paths
      regulator: s5m8767: Use scoped device node handling to simplify error paths
      regulator: qcom-rpmh: Simplify with scoped for each OF child loop
      regulator: qcom-smd: Simplify with scoped for each OF child loop
      regulator: scmi: Simplify with scoped for each OF child loop

 drivers/regulator/bd718x7-regulator.c   | 19 ++++++-------------
 drivers/regulator/bd96801-regulator.c   | 17 ++++++-----------
 drivers/regulator/max8997-regulator.c   | 11 +++++------
 drivers/regulator/qcom-rpmh-regulator.c | 11 +++--------
 drivers/regulator/qcom_smd-regulator.c  | 11 +++--------
 drivers/regulator/s5m8767.c             | 17 ++++++-----------
 drivers/regulator/scmi-regulator.c      |  8 +++-----
 7 files changed, 32 insertions(+), 62 deletions(-)
---
base-commit: 7b3754ef5d53bb1431e25f65126280993c2e640b
change-id: 20240814-cleanup-h-of-node-put-regulator-80df40883f35

Best regards,
-- 
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/7] regulator: bd718x7: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-15  5:15   ` Matti Vaittinen
  2024-08-14 15:04 ` [PATCH 2/7] regulator: bd96801: " Krzysztof Kozlowski
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

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.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/regulator/bd718x7-regulator.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c
index c3fb05dce40c..1bb048de3ecd 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -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)

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/7] regulator: bd96801: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 1/7] regulator: bd718x7: " Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-15  5:29   ` Matti Vaittinen
  2024-08-14 15:04 ` [PATCH 3/7] regulator: max8997: " Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

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>
---
 drivers/regulator/bd96801-regulator.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/bd96801-regulator.c b/drivers/regulator/bd96801-regulator.c
index ec5b1a6b19e8..9876cc05867e 100644
--- a/drivers/regulator/bd96801-regulator.c
+++ b/drivers/regulator/bd96801-regulator.c
@@ -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;
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/7] regulator: max8997: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 1/7] regulator: bd718x7: " Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 2/7] regulator: bd96801: " Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 4/7] regulator: s5m8767: " Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

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>
---
 drivers/regulator/max8997-regulator.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/max8997-regulator.c b/drivers/regulator/max8997-regulator.c
index cdbfb4561dd8..e77621b6466c 100644
--- a/drivers/regulator/max8997-regulator.c
+++ b/drivers/regulator/max8997-regulator.c
@@ -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");

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/7] regulator: s5m8767: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2024-08-14 15:04 ` [PATCH 3/7] regulator: max8997: " Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 5/7] regulator: qcom-rpmh: Simplify with scoped for each OF child loop Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

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>
---
 drivers/regulator/s5m8767.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index bfc0e143bf40..d25cd81e3f36 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -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;
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/7] regulator: qcom-rpmh: Simplify with scoped for each OF child loop
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2024-08-14 15:04 ` [PATCH 4/7] regulator: s5m8767: " Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 6/7] regulator: qcom-smd: " Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/regulator/qcom-rpmh-regulator.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/regulator/qcom-rpmh-regulator.c b/drivers/regulator/qcom-rpmh-regulator.c
index 80e304711345..6b4cb7ba49c7 100644
--- a/drivers/regulator/qcom-rpmh-regulator.c
+++ b/drivers/regulator/qcom-rpmh-regulator.c
@@ -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;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/7] regulator: qcom-smd: Simplify with scoped for each OF child loop
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2024-08-14 15:04 ` [PATCH 5/7] regulator: qcom-rpmh: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-14 15:04 ` [PATCH 7/7] regulator: scmi: " Krzysztof Kozlowski
  2024-08-15 14:43 ` [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Mark Brown
  7 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/regulator/qcom_smd-regulator.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/regulator/qcom_smd-regulator.c b/drivers/regulator/qcom_smd-regulator.c
index 3b7e06b9f5ce..6761ada0cf7d 100644
--- a/drivers/regulator/qcom_smd-regulator.c
+++ b/drivers/regulator/qcom_smd-regulator.c
@@ -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;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/7] regulator: scmi: Simplify with scoped for each OF child loop
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2024-08-14 15:04 ` [PATCH 6/7] regulator: qcom-smd: " Krzysztof Kozlowski
@ 2024-08-14 15:04 ` Krzysztof Kozlowski
  2024-08-15 14:43 ` [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Mark Brown
  7 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 15:04 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Mark Brown, Krzysztof Kozlowski,
	Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel, Krzysztof Kozlowski

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/regulator/scmi-regulator.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/scmi-regulator.c b/drivers/regulator/scmi-regulator.c
index 29ab217297d6..9df726f10ad1 100644
--- a/drivers/regulator/scmi-regulator.c
+++ b/drivers/regulator/scmi-regulator.c
@@ -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);
 	/*

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/7] regulator: bd718x7: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 ` [PATCH 1/7] regulator: bd718x7: " Krzysztof Kozlowski
@ 2024-08-15  5:15   ` Matti Vaittinen
  0 siblings, 0 replies; 11+ messages in thread
From: Matti Vaittinen @ 2024-08-15  5:15 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Liam Girdwood, Mark Brown,
	Krzysztof Kozlowski, Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel

On 8/14/24 18:04, Krzysztof Kozlowski wrote:
> 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.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Acked-by: Matti Vaittinen <mazziesaccount@gmail.com>

Thanks Krzysztof! I've been a bit cautious to what comes to using the 
cleanup attribute. Well, I suppose it's a time for me to admit it 
simplifies things - even if it breaks the rules which were carved to a 
stone for a long time :) So ... Thanks!

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/7] regulator: bd96801: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 ` [PATCH 2/7] regulator: bd96801: " Krzysztof Kozlowski
@ 2024-08-15  5:29   ` Matti Vaittinen
  0 siblings, 0 replies; 11+ messages in thread
From: Matti Vaittinen @ 2024-08-15  5:29 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Liam Girdwood, Mark Brown,
	Krzysztof Kozlowski, Sudeep Holla, Cristian Marussi
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel

On 8/14/24 18:04, Krzysztof Kozlowski wrote:
> 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>

Acked-by: Matti Vaittinen <mazziesaccount@gmail.com>

Yours,
	-- Matti

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths
  2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
                   ` (6 preceding siblings ...)
  2024-08-14 15:04 ` [PATCH 7/7] regulator: scmi: " Krzysztof Kozlowski
@ 2024-08-15 14:43 ` Mark Brown
  7 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2024-08-15 14:43 UTC (permalink / raw)
  To: Matti Vaittinen, Liam Girdwood, Krzysztof Kozlowski, Sudeep Holla,
	Cristian Marussi, Krzysztof Kozlowski
  Cc: linux-kernel, linux-samsung-soc, linux-arm-msm, arm-scmi,
	linux-arm-kernel

On Wed, 14 Aug 2024 17:04:04 +0200, Krzysztof Kozlowski wrote:
> Make code a bit smaller/simpler, with less of_node_put() thanks to
> cleanup.h.
> 
> Best regards,
> Krzysztof
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/7] regulator: bd718x7: Use scoped device node handling to simplify error paths
      commit: 83c7cdeef5b22a73336eb18a59c7b4d63ec26659
[2/7] regulator: bd96801: Use scoped device node handling to simplify error paths
      commit: f372c262d4cfe31f0b67e8ae1a8ec9bf7c52d57b
[3/7] regulator: max8997: Use scoped device node handling to simplify error paths
      commit: ea13bd391d1b8f62ae2347bde7a174059d7f3f0d
[4/7] regulator: s5m8767: Use scoped device node handling to simplify error paths
      commit: 34a3f95941e0dfee750f2fd28faed4c8cd7ee42c
[5/7] regulator: qcom-rpmh: Simplify with scoped for each OF child loop
      commit: 17636d443fbe376d5192a7ce6a444aa45ce45541
[6/7] regulator: qcom-smd: Simplify with scoped for each OF child loop
      commit: d4cd75b8eff72d65dab63668d5d883d72dda0426
[7/7] regulator: scmi: Simplify with scoped for each OF child loop
      commit: 99cf5db9cdd39136fd5dbd10bda833aa0f870452

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-08-15 14:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 15:04 [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-08-14 15:04 ` [PATCH 1/7] regulator: bd718x7: " Krzysztof Kozlowski
2024-08-15  5:15   ` Matti Vaittinen
2024-08-14 15:04 ` [PATCH 2/7] regulator: bd96801: " Krzysztof Kozlowski
2024-08-15  5:29   ` Matti Vaittinen
2024-08-14 15:04 ` [PATCH 3/7] regulator: max8997: " Krzysztof Kozlowski
2024-08-14 15:04 ` [PATCH 4/7] regulator: s5m8767: " Krzysztof Kozlowski
2024-08-14 15:04 ` [PATCH 5/7] regulator: qcom-rpmh: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-14 15:04 ` [PATCH 6/7] regulator: qcom-smd: " Krzysztof Kozlowski
2024-08-14 15:04 ` [PATCH 7/7] regulator: scmi: " Krzysztof Kozlowski
2024-08-15 14:43 ` [PATCH 0/7] regulator: Use scoped device node handling to simplify error paths Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox