linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] thermal: scope/cleanup.h improvements
@ 2024-08-14 20:17 Krzysztof Kozlowski
  2024-08-14 20:17 ` [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, Krzysztof Kozlowski

Few code simplifications with scope/cleanup.h.

One of thermal_of.c patches depends on my earlier fixes:
https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/

Best regards,
Krzysztof

---
Krzysztof Kozlowski (7):
      thermal: of: Use scoped device node handling to simplify of_find_trip_id()
      thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
      thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
      thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
      thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop
      thermal: tegra: Simplify with scoped for each OF child loop
      thermal: sun8i: Use scoped device node handling to simplify error paths

 drivers/thermal/qcom/qcom-spmi-adc-tm5.c |  7 ++--
 drivers/thermal/sun8i_thermal.c          | 11 +++---
 drivers/thermal/tegra/soctherm.c         |  5 ++-
 drivers/thermal/thermal_of.c             | 60 ++++++++++----------------------
 4 files changed, 28 insertions(+), 55 deletions(-)
---
base-commit: aef749dad7ff4c301e91b21fadf30776c1495fa8
change-id: 20240814-b4-cleanup-h-of-node-put-thermal-2268440cc6f7

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



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

* [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id()
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:10   ` Chen-Yu Tsai
  2024-08-14 20:17 ` [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, Krzysztof Kozlowski

Obtain the device node reference with scoped/cleanup.h and use scoped
for_each_child_of_node_scoped() to reduce error handling in
of_find_trip_id() and make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/thermal/thermal_of.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 1f252692815a..a2278d4ad886 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/cleanup.h>
 #include <linux/err.h>
 #include <linux/export.h>
 #include <linux/of.h>
@@ -22,11 +23,9 @@
 
 static int of_find_trip_id(struct device_node *np, struct device_node *trip)
 {
-	struct device_node *trips;
-	struct device_node *t;
 	int i = 0;
 
-	trips = of_get_child_by_name(np, "trips");
+	struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
 	if (!trips) {
 		pr_err("Failed to find 'trips' node\n");
 		return -EINVAL;
@@ -35,20 +34,13 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip)
 	/*
 	 * Find the trip id point associated with the cooling device map
 	 */
-	for_each_child_of_node(trips, t) {
-
-		if (t == trip) {
-			of_node_put(t);
-			goto out;
-		}
+	for_each_child_of_node_scoped(trips, t) {
+		if (t == trip)
+			return i;
 		i++;
 	}
 
-	i = -ENXIO;
-out:
-	of_node_put(trips);
-
-	return i;
+	return -ENXIO;
 }
 
 /*

-- 
2.43.0



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

* [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
  2024-08-14 20:17 ` [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:15   ` Chen-Yu Tsai
  2024-08-14 20:17 ` [PATCH 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, 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/thermal/thermal_of.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index a2278d4ad886..c8ded4462bb8 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -117,10 +117,9 @@ static int thermal_of_populate_trip(struct device_node *np,
 static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips)
 {
 	struct thermal_trip *tt;
-	struct device_node *trips;
 	int ret, count;
 
-	trips = of_get_child_by_name(np, "trips");
+	struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
 	if (!trips) {
 		pr_err("Failed to find 'trips' node\n");
 		return ERR_PTR(-EINVAL);
@@ -129,15 +128,12 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
 	count = of_get_child_count(trips);
 	if (!count) {
 		pr_err("No trip point defined\n");
-		ret = -EINVAL;
-		goto out_of_node_put;
+		return ERR_PTR(-EINVAL);
 	}
 
 	tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
-	if (!tt) {
-		ret = -ENOMEM;
-		goto out_of_node_put;
-	}
+	if (!tt)
+		return ERR_PTR(-ENOMEM);
 
 	*ntrips = count;
 
@@ -155,8 +151,6 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
 out_kfree:
 	kfree(tt);
 	*ntrips = 0;
-out_of_node_put:
-	of_node_put(trips);
 
 	return ERR_PTR(ret);
 }

-- 
2.43.0



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

* [PATCH 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
  2024-08-14 20:17 ` [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
  2024-08-14 20:17 ` [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:19   ` Chen-Yu Tsai
  2024-08-14 20:17 ` [PATCH 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, 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>

---

This depends on my earlier fixes:

https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/
---
 drivers/thermal/thermal_of.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index c8ded4462bb8..fb5472d6ffea 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -157,10 +157,9 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
 
 static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id)
 {
-	struct device_node *np, *tz;
 	struct of_phandle_args sensor_specs;
 
-	np = of_find_node_by_name(NULL, "thermal-zones");
+	struct device_node *np __free(device_node) = of_find_node_by_name(NULL, "thermal-zones");
 	if (!np) {
 		pr_debug("No thermal zones description\n");
 		return ERR_PTR(-ENODEV);
@@ -178,8 +177,7 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
 						   "#thermal-sensor-cells");
 		if (count <= 0) {
 			pr_err("%pOFn: missing thermal sensor\n", child);
-			tz = ERR_PTR(-EINVAL);
-			goto out;
+			return ERR_PTR(-EINVAL);
 		}
 
 		for (i = 0; i < count; i++) {
@@ -191,22 +189,18 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
 							 i, &sensor_specs);
 			if (ret < 0) {
 				pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", child, ret);
-				tz = ERR_PTR(ret);
-				goto out;
+				return ERR_PTR(ret);
 			}
 
 			if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
 								  sensor_specs.args[0] : 0)) {
 				pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, child);
-				tz = no_free_ptr(child);
-				goto out;
+				return no_free_ptr(child);
 			}
 		}
 	}
-	tz = ERR_PTR(-ENODEV);
-out:
-	of_node_put(np);
-	return tz;
+
+	return ERR_PTR(-ENODEV);
 }
 
 static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdelay)

-- 
2.43.0



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

* [PATCH 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2024-08-14 20:17 ` [PATCH 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:22   ` Chen-Yu Tsai
  2024-08-14 20:17 ` [PATCH 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, Krzysztof Kozlowski

Use scoped for_each_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/thermal/thermal_of.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index fb5472d6ffea..d277165746d5 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -375,7 +375,7 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
 					    int (*action)(struct device_node *, int, int,
 							  struct thermal_zone_device *, struct thermal_cooling_device *))
 {
-	struct device_node *tz_np, *cm_np, *child;
+	struct device_node *tz_np, *cm_np;
 	int ret = 0;
 
 	tz_np = thermal_of_zone_get_by_name(tz);
@@ -388,12 +388,10 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
 	if (!cm_np)
 		goto out;
 
-	for_each_child_of_node(cm_np, child) {
+	for_each_child_of_node_scoped(cm_np, child) {
 		ret = thermal_of_for_each_cooling_device(tz_np, child, tz, cdev, action);
-		if (ret) {
-			of_node_put(child);
+		if (ret)
 			break;
-		}
 	}
 
 	of_node_put(cm_np);

-- 
2.43.0



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

* [PATCH 5/7] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2024-08-14 20:17 ` [PATCH 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:29   ` Chen-Yu Tsai
  2024-08-14 20:17 ` [PATCH 6/7] thermal: tegra: " Krzysztof Kozlowski
  2024-08-14 20:17 ` [PATCH 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, 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/thermal/qcom/qcom-spmi-adc-tm5.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
index 7c9f4023babc..19cdb98c310e 100644
--- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
+++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
@@ -938,7 +938,6 @@ static const struct adc_tm5_data adc_tm5_gen2_data_pmic = {
 static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node *node)
 {
 	struct adc_tm5_channel *channels;
-	struct device_node *child;
 	u32 value;
 	int ret;
 	struct device *dev = adc_tm->dev;
@@ -982,12 +981,10 @@ static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node *
 		adc_tm->avg_samples = VADC_DEF_AVG_SAMPLES;
 	}
 
-	for_each_available_child_of_node(node, child) {
+	for_each_available_child_of_node_scoped(node, child) {
 		ret = adc_tm5_get_dt_channel_data(adc_tm, channels, child);
-		if (ret) {
-			of_node_put(child);
+		if (ret)
 			return ret;
-		}
 
 		channels++;
 	}

-- 
2.43.0



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

* [PATCH 6/7] thermal: tegra: Simplify with scoped for each OF child loop
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2024-08-14 20:17 ` [PATCH 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:31   ` Chen-Yu Tsai
  2024-08-14 20:17 ` [PATCH 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, Krzysztof Kozlowski

Use scoped for_each_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/thermal/tegra/soctherm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index a023c948afbd..ff4eedb553fb 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -1651,7 +1651,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct tegra_soctherm *ts = dev_get_drvdata(dev);
-	struct device_node *np_stc, *np_stcc;
+	struct device_node *np_stc;
 	const char *name;
 	int i;
 
@@ -1668,7 +1668,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
 		return;
 	}
 
-	for_each_child_of_node(np_stc, np_stcc) {
+	for_each_child_of_node_scoped(np_stc, np_stcc) {
 		struct soctherm_throt_cfg *stc;
 		struct thermal_cooling_device *tcd;
 		int err;
@@ -1683,7 +1683,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
 
 		if (stc->init) {
 			dev_err(dev, "throttle-cfg: %s: redefined!\n", name);
-			of_node_put(np_stcc);
 			break;
 		}
 

-- 
2.43.0



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

* [PATCH 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths
  2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2024-08-14 20:17 ` [PATCH 6/7] thermal: tegra: " Krzysztof Kozlowski
@ 2024-08-14 20:17 ` Krzysztof Kozlowski
  2024-08-15  7:33   ` Chen-Yu Tsai
  6 siblings, 1 reply; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-14 20:17 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-kernel, linux-arm-msm, linux-tegra,
	linux-arm-kernel, linux-sunxi, 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/thermal/sun8i_thermal.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index 3203d8bd13a8..22674790629a 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -9,6 +9,7 @@
  */
 
 #include <linux/bitmap.h>
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
@@ -348,19 +349,18 @@ static void sun8i_ths_reset_control_assert(void *data)
 
 static struct regmap *sun8i_ths_get_sram_regmap(struct device_node *node)
 {
-	struct device_node *sram_node;
 	struct platform_device *sram_pdev;
 	struct regmap *regmap = NULL;
 
-	sram_node = of_parse_phandle(node, "allwinner,sram", 0);
+	struct device_node *sram_node __free(device_node) =
+		of_parse_phandle(node, "allwinner,sram", 0);
 	if (!sram_node)
 		return ERR_PTR(-ENODEV);
 
 	sram_pdev = of_find_device_by_node(sram_node);
 	if (!sram_pdev) {
 		/* platform device might not be probed yet */
-		regmap = ERR_PTR(-EPROBE_DEFER);
-		goto out_put_node;
+		return ERR_PTR(-EPROBE_DEFER);
 	}
 
 	/* If no regmap is found then the other device driver is at fault */
@@ -369,8 +369,7 @@ static struct regmap *sun8i_ths_get_sram_regmap(struct device_node *node)
 		regmap = ERR_PTR(-EINVAL);
 
 	platform_device_put(sram_pdev);
-out_put_node:
-	of_node_put(sram_node);
+
 	return regmap;
 }
 

-- 
2.43.0



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

* Re: [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id()
  2024-08-14 20:17 ` [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
@ 2024-08-15  7:10   ` Chen-Yu Tsai
  0 siblings, 0 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:10 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:47PM +0200, 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 in
> of_find_trip_id() and make the code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
>  drivers/thermal/thermal_of.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index 1f252692815a..a2278d4ad886 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -8,6 +8,7 @@
>  
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
> +#include <linux/cleanup.h>
>  #include <linux/err.h>
>  #include <linux/export.h>
>  #include <linux/of.h>
> @@ -22,11 +23,9 @@
>  
>  static int of_find_trip_id(struct device_node *np, struct device_node *trip)
>  {
> -	struct device_node *trips;
> -	struct device_node *t;
>  	int i = 0;
>  
> -	trips = of_get_child_by_name(np, "trips");
> +	struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
>  	if (!trips) {
>  		pr_err("Failed to find 'trips' node\n");
>  		return -EINVAL;
> @@ -35,20 +34,13 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip)
>  	/*
>  	 * Find the trip id point associated with the cooling device map
>  	 */
> -	for_each_child_of_node(trips, t) {
> -
> -		if (t == trip) {
> -			of_node_put(t);
> -			goto out;
> -		}
> +	for_each_child_of_node_scoped(trips, t) {
> +		if (t == trip)
> +			return i;
>  		i++;
>  	}
>  
> -	i = -ENXIO;
> -out:
> -	of_node_put(trips);
> -
> -	return i;
> +	return -ENXIO;
>  }
>  
>  /*
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
  2024-08-14 20:17 ` [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
@ 2024-08-15  7:15   ` Chen-Yu Tsai
  2024-08-16  5:28     ` Krzysztof Kozlowski
  2024-08-17  2:47     ` Dragan Simic
  0 siblings, 2 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:15 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:48PM +0200, Krzysztof Kozlowski wrote:
> 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/thermal/thermal_of.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index a2278d4ad886..c8ded4462bb8 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -117,10 +117,9 @@ static int thermal_of_populate_trip(struct device_node *np,
>  static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips)
>  {
>  	struct thermal_trip *tt;
> -	struct device_node *trips;
>  	int ret, count;
>  
> -	trips = of_get_child_by_name(np, "trips");
> +	struct device_node *trips __free(device_node) = of_get_child_by_name(np, "trips");
>  	if (!trips) {
>  		pr_err("Failed to find 'trips' node\n");
>  		return ERR_PTR(-EINVAL);
> @@ -129,15 +128,12 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
>  	count = of_get_child_count(trips);
>  	if (!count) {
>  		pr_err("No trip point defined\n");
> -		ret = -EINVAL;
> -		goto out_of_node_put;
> +		return ERR_PTR(-EINVAL);
>  	}
>  
>  	tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
> -	if (!tt) {
> -		ret = -ENOMEM;
> -		goto out_of_node_put;
> -	}
> +	if (!tt)
> +		return ERR_PTR(-ENOMEM);
>  
>  	*ntrips = count;

Also drop the "of_node_put(trips);" in the successful path?

Once fixed,

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

And I plan to send a patch on top of this making "tt" auto released,
thereby eliminating the error path.

>  
> @@ -155,8 +151,6 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
>  out_kfree:
>  	kfree(tt);
>  	*ntrips = 0;
> -out_of_node_put:
> -	of_node_put(trips);
>  
>  	return ERR_PTR(ret);
>  }
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
  2024-08-14 20:17 ` [PATCH 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
@ 2024-08-15  7:19   ` Chen-Yu Tsai
  0 siblings, 0 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:49PM +0200, Krzysztof Kozlowski wrote:
> 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>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
> 
> This depends on my earlier fixes:
> 
> https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/
> ---
>  drivers/thermal/thermal_of.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index c8ded4462bb8..fb5472d6ffea 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -157,10 +157,9 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
>  
>  static struct device_node *of_thermal_zone_find(struct device_node *sensor, int id)
>  {
> -	struct device_node *np, *tz;
>  	struct of_phandle_args sensor_specs;
>  
> -	np = of_find_node_by_name(NULL, "thermal-zones");
> +	struct device_node *np __free(device_node) = of_find_node_by_name(NULL, "thermal-zones");
>  	if (!np) {
>  		pr_debug("No thermal zones description\n");
>  		return ERR_PTR(-ENODEV);
> @@ -178,8 +177,7 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
>  						   "#thermal-sensor-cells");
>  		if (count <= 0) {
>  			pr_err("%pOFn: missing thermal sensor\n", child);
> -			tz = ERR_PTR(-EINVAL);
> -			goto out;
> +			return ERR_PTR(-EINVAL);
>  		}
>  
>  		for (i = 0; i < count; i++) {
> @@ -191,22 +189,18 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int
>  							 i, &sensor_specs);
>  			if (ret < 0) {
>  				pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", child, ret);
> -				tz = ERR_PTR(ret);
> -				goto out;
> +				return ERR_PTR(ret);
>  			}
>  
>  			if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ?
>  								  sensor_specs.args[0] : 0)) {
>  				pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, child);
> -				tz = no_free_ptr(child);
> -				goto out;
> +				return no_free_ptr(child);
>  			}
>  		}
>  	}
> -	tz = ERR_PTR(-ENODEV);
> -out:
> -	of_node_put(np);
> -	return tz;
> +
> +	return ERR_PTR(-ENODEV);
>  }
>  
>  static int thermal_of_monitor_init(struct device_node *np, int *delay, int *pdelay)
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
  2024-08-14 20:17 ` [PATCH 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-15  7:22   ` Chen-Yu Tsai
  0 siblings, 0 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:22 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:50PM +0200, Krzysztof Kozlowski wrote:
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
>  drivers/thermal/thermal_of.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index fb5472d6ffea..d277165746d5 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -375,7 +375,7 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
>  					    int (*action)(struct device_node *, int, int,
>  							  struct thermal_zone_device *, struct thermal_cooling_device *))
>  {
> -	struct device_node *tz_np, *cm_np, *child;
> +	struct device_node *tz_np, *cm_np;

Looks like the remaining two pointers are also candidates for cleanup?

>  	int ret = 0;
>  
>  	tz_np = thermal_of_zone_get_by_name(tz);
> @@ -388,12 +388,10 @@ static int thermal_of_for_each_cooling_maps(struct thermal_zone_device *tz,
>  	if (!cm_np)
>  		goto out;
>  
> -	for_each_child_of_node(cm_np, child) {
> +	for_each_child_of_node_scoped(cm_np, child) {
>  		ret = thermal_of_for_each_cooling_device(tz_np, child, tz, cdev, action);
> -		if (ret) {
> -			of_node_put(child);
> +		if (ret)
>  			break;
> -		}
>  	}
>  
>  	of_node_put(cm_np);
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 5/7] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop
  2024-08-14 20:17 ` [PATCH 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
@ 2024-08-15  7:29   ` Chen-Yu Tsai
  0 siblings, 0 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:29 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:51PM +0200, Krzysztof Kozlowski wrote:
> 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>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
>  drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
> index 7c9f4023babc..19cdb98c310e 100644
> --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
> +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c
> @@ -938,7 +938,6 @@ static const struct adc_tm5_data adc_tm5_gen2_data_pmic = {
>  static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node *node)
>  {
>  	struct adc_tm5_channel *channels;
> -	struct device_node *child;
>  	u32 value;
>  	int ret;
>  	struct device *dev = adc_tm->dev;
> @@ -982,12 +981,10 @@ static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node *
>  		adc_tm->avg_samples = VADC_DEF_AVG_SAMPLES;
>  	}
>  
> -	for_each_available_child_of_node(node, child) {
> +	for_each_available_child_of_node_scoped(node, child) {
>  		ret = adc_tm5_get_dt_channel_data(adc_tm, channels, child);
> -		if (ret) {
> -			of_node_put(child);
> +		if (ret)
>  			return ret;
> -		}
>  
>  		channels++;
>  	}
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 6/7] thermal: tegra: Simplify with scoped for each OF child loop
  2024-08-14 20:17 ` [PATCH 6/7] thermal: tegra: " Krzysztof Kozlowski
@ 2024-08-15  7:31   ` Chen-Yu Tsai
  0 siblings, 0 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:31 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:52PM +0200, Krzysztof Kozlowski wrote:
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
>  drivers/thermal/tegra/soctherm.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
> index a023c948afbd..ff4eedb553fb 100644
> --- a/drivers/thermal/tegra/soctherm.c
> +++ b/drivers/thermal/tegra/soctherm.c
> @@ -1651,7 +1651,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  	struct tegra_soctherm *ts = dev_get_drvdata(dev);
> -	struct device_node *np_stc, *np_stcc;
> +	struct device_node *np_stc;
>  	const char *name;
>  	int i;
>  
> @@ -1668,7 +1668,7 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
>  		return;
>  	}
>  
> -	for_each_child_of_node(np_stc, np_stcc) {
> +	for_each_child_of_node_scoped(np_stc, np_stcc) {
>  		struct soctherm_throt_cfg *stc;
>  		struct thermal_cooling_device *tcd;
>  		int err;
> @@ -1683,7 +1683,6 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev)
>  
>  		if (stc->init) {
>  			dev_err(dev, "throttle-cfg: %s: redefined!\n", name);
> -			of_node_put(np_stcc);
>  			break;
>  		}
>  
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths
  2024-08-14 20:17 ` [PATCH 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-15  7:33   ` Chen-Yu Tsai
  0 siblings, 0 replies; 17+ messages in thread
From: Chen-Yu Tsai @ 2024-08-15  7:33 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On Wed, Aug 14, 2024 at 10:17:53PM +0200, Krzysztof Kozlowski wrote:
> 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>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

> ---
>  drivers/thermal/sun8i_thermal.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
> index 3203d8bd13a8..22674790629a 100644
> --- a/drivers/thermal/sun8i_thermal.c
> +++ b/drivers/thermal/sun8i_thermal.c
> @@ -9,6 +9,7 @@
>   */
>  
>  #include <linux/bitmap.h>
> +#include <linux/cleanup.h>
>  #include <linux/clk.h>
>  #include <linux/device.h>
>  #include <linux/interrupt.h>
> @@ -348,19 +349,18 @@ static void sun8i_ths_reset_control_assert(void *data)
>  
>  static struct regmap *sun8i_ths_get_sram_regmap(struct device_node *node)
>  {
> -	struct device_node *sram_node;
>  	struct platform_device *sram_pdev;
>  	struct regmap *regmap = NULL;
>  
> -	sram_node = of_parse_phandle(node, "allwinner,sram", 0);
> +	struct device_node *sram_node __free(device_node) =
> +		of_parse_phandle(node, "allwinner,sram", 0);
>  	if (!sram_node)
>  		return ERR_PTR(-ENODEV);
>  
>  	sram_pdev = of_find_device_by_node(sram_node);
>  	if (!sram_pdev) {
>  		/* platform device might not be probed yet */
> -		regmap = ERR_PTR(-EPROBE_DEFER);
> -		goto out_put_node;
> +		return ERR_PTR(-EPROBE_DEFER);
>  	}
>  
>  	/* If no regmap is found then the other device driver is at fault */
> @@ -369,8 +369,7 @@ static struct regmap *sun8i_ths_get_sram_regmap(struct device_node *node)
>  		regmap = ERR_PTR(-EINVAL);
>  
>  	platform_device_put(sram_pdev);
> -out_put_node:
> -	of_node_put(sram_node);
> +
>  	return regmap;
>  }
>  
> 
> -- 
> 2.43.0
> 


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

* Re: [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
  2024-08-15  7:15   ` Chen-Yu Tsai
@ 2024-08-16  5:28     ` Krzysztof Kozlowski
  2024-08-17  2:47     ` Dragan Simic
  1 sibling, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16  5:28 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Amit Kucheria, Thara Gopinath, Thierry Reding, Jonathan Hunter,
	Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, linux-pm, linux-kernel, linux-arm-msm,
	linux-tegra, linux-arm-kernel, linux-sunxi

On 15/08/2024 09:15, Chen-Yu Tsai wrote:
>>  
>>  	tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
>> -	if (!tt) {
>> -		ret = -ENOMEM;
>> -		goto out_of_node_put;
>> -	}
>> +	if (!tt)
>> +		return ERR_PTR(-ENOMEM);
>>  
>>  	*ntrips = count;
> 
> Also drop the "of_node_put(trips);" in the successful path?
> 

Right.

Best regards,
Krzysztof



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

* Re: [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
  2024-08-15  7:15   ` Chen-Yu Tsai
  2024-08-16  5:28     ` Krzysztof Kozlowski
@ 2024-08-17  2:47     ` Dragan Simic
  1 sibling, 0 replies; 17+ messages in thread
From: Dragan Simic @ 2024-08-17  2:47 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Krzysztof Kozlowski, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
	Lukasz Luba, Amit Kucheria, Thara Gopinath, Thierry Reding,
	Jonathan Hunter, Vasily Khoruzhick, Yangtao Li, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland, linux-pm, linux-kernel,
	linux-arm-msm, linux-tegra, linux-arm-kernel, linux-sunxi

On 2024-08-15 09:15, Chen-Yu Tsai wrote:
> On Wed, Aug 14, 2024 at 10:17:48PM +0200, Krzysztof Kozlowski wrote:
>> 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/thermal/thermal_of.c | 14 ++++----------
>>  1 file changed, 4 insertions(+), 10 deletions(-)
>> 
>> diff --git a/drivers/thermal/thermal_of.c 
>> b/drivers/thermal/thermal_of.c
>> index a2278d4ad886..c8ded4462bb8 100644
>> --- a/drivers/thermal/thermal_of.c
>> +++ b/drivers/thermal/thermal_of.c
>> @@ -117,10 +117,9 @@ static int thermal_of_populate_trip(struct 
>> device_node *np,
>>  static struct thermal_trip *thermal_of_trips_init(struct device_node 
>> *np, int *ntrips)
>>  {
>>  	struct thermal_trip *tt;
>> -	struct device_node *trips;
>>  	int ret, count;
>> 
>> -	trips = of_get_child_by_name(np, "trips");
>> +	struct device_node *trips __free(device_node) = 
>> of_get_child_by_name(np, "trips");
>>  	if (!trips) {
>>  		pr_err("Failed to find 'trips' node\n");
>>  		return ERR_PTR(-EINVAL);
>> @@ -129,15 +128,12 @@ static struct thermal_trip 
>> *thermal_of_trips_init(struct device_node *np, int *n
>>  	count = of_get_child_count(trips);
>>  	if (!count) {
>>  		pr_err("No trip point defined\n");
>> -		ret = -EINVAL;
>> -		goto out_of_node_put;
>> +		return ERR_PTR(-EINVAL);
>>  	}
>> 
>>  	tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
>> -	if (!tt) {
>> -		ret = -ENOMEM;
>> -		goto out_of_node_put;
>> -	}
>> +	if (!tt)
>> +		return ERR_PTR(-ENOMEM);
>> 
>>  	*ntrips = count;
> 
> Also drop the "of_node_put(trips);" in the successful path?
> 
> Once fixed,
> 
> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
> 
> And I plan to send a patch on top of this making "tt" auto released,
> thereby eliminating the error path.

Ah, with that additional patch in place, I totally agree with
moving "*ntrips = 0" to the top.

>> @@ -155,8 +151,6 @@ static struct thermal_trip 
>> *thermal_of_trips_init(struct device_node *np, int *n
>>  out_kfree:
>>  	kfree(tt);
>>  	*ntrips = 0;
>> -out_of_node_put:
>> -	of_node_put(trips);
>> 
>>  	return ERR_PTR(ret);
>>  }
>> 
>> --
>> 2.43.0
>> 


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

end of thread, other threads:[~2024-08-17  2:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 20:17 [PATCH 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-08-14 20:17 ` [PATCH 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
2024-08-15  7:10   ` Chen-Yu Tsai
2024-08-14 20:17 ` [PATCH 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
2024-08-15  7:15   ` Chen-Yu Tsai
2024-08-16  5:28     ` Krzysztof Kozlowski
2024-08-17  2:47     ` Dragan Simic
2024-08-14 20:17 ` [PATCH 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
2024-08-15  7:19   ` Chen-Yu Tsai
2024-08-14 20:17 ` [PATCH 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
2024-08-15  7:22   ` Chen-Yu Tsai
2024-08-14 20:17 ` [PATCH 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
2024-08-15  7:29   ` Chen-Yu Tsai
2024-08-14 20:17 ` [PATCH 6/7] thermal: tegra: " Krzysztof Kozlowski
2024-08-15  7:31   ` Chen-Yu Tsai
2024-08-14 20:17 ` [PATCH 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-08-15  7:33   ` Chen-Yu Tsai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).