* [PATCH v2 0/7] thermal: scope/cleanup.h improvements
@ 2024-08-16 7:40 Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Changes in v2:
- Drop left-over of_node_put in regular exit path (Chen-Yu)
- Link to v1: https://lore.kernel.org/r/20240814-b4-cleanup-h-of-node-put-thermal-v1-0-7a1381e1627e@linaro.org
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 | 62 ++++++++++----------------------
4 files changed, 28 insertions(+), 57 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] 11+ messages in thread
* [PATCH v2 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id()
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, 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.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
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] 11+ messages in thread
* [PATCH v2 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Changes in v2:
1. Drop left-over of_node_put in regular exit path (Chen-Yu)
---
drivers/thermal/thermal_of.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index a2278d4ad886..2a50910f35d3 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;
@@ -148,15 +144,11 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n
goto out_kfree;
}
- of_node_put(trips);
-
return tt;
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] 11+ messages in thread
* [PATCH v2 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 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, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
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 2a50910f35d3..94cc077ab3a1 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -155,10 +155,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);
@@ -176,8 +175,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++) {
@@ -189,22 +187,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] 11+ messages in thread
* [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (2 preceding siblings ...)
2024-08-16 7:40 ` [PATCH v2 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
2024-08-16 11:30 ` Rafael J. Wysocki
2024-08-16 7:40 ` [PATCH v2 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
` (2 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
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 94cc077ab3a1..ce398fde48bb 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -373,7 +373,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);
@@ -386,12 +386,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] 11+ messages in thread
* [PATCH v2 5/7] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (3 preceding siblings ...)
2024-08-16 7:40 ` [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 6/7] thermal: tegra: " Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
6 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
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] 11+ messages in thread
* [PATCH v2 6/7] thermal: tegra: Simplify with scoped for each OF child loop
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (4 preceding siblings ...)
2024-08-16 7:40 ` [PATCH v2 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
6 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
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] 11+ messages in thread
* [PATCH v2 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (5 preceding siblings ...)
2024-08-16 7:40 ` [PATCH v2 6/7] thermal: tegra: " Krzysztof Kozlowski
@ 2024-08-16 7:40 ` Krzysztof Kozlowski
6 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 7:40 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, Chen-Yu Tsai, Krzysztof Kozlowski
Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
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] 11+ messages in thread
* Re: [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
2024-08-16 7:40 ` [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 11:30 ` Rafael J. Wysocki
2024-08-16 12:21 ` Krzysztof Kozlowski
0 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2024-08-16 11:30 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, Chen-Yu Tsai
On Fri, Aug 16, 2024 at 9:40 AM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> Use scoped for_each_child_of_node_scoped() when iterating over device
> nodes to make code a bit simpler.
>
> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
> 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 94cc077ab3a1..ce398fde48bb 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -373,7 +373,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);
> @@ -386,12 +386,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);
>
> --
This clashes with
https://lore.kernel.org/linux-pm/1758256.QkHrqEjB74@rjwysocki.net/
which I would prefer to go in first if you don't mind.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
2024-08-16 11:30 ` Rafael J. Wysocki
@ 2024-08-16 12:21 ` Krzysztof Kozlowski
2024-08-16 16:02 ` Rafael J. Wysocki
0 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 12:21 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: 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, Chen-Yu Tsai
On 16/08/2024 13:30, Rafael J. Wysocki wrote:
> On Fri, Aug 16, 2024 at 9:40 AM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> Use scoped for_each_child_of_node_scoped() when iterating over device
>> nodes to make code a bit simpler.
>>
>> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
>> 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 94cc077ab3a1..ce398fde48bb 100644
>> --- a/drivers/thermal/thermal_of.c
>> +++ b/drivers/thermal/thermal_of.c
>> @@ -373,7 +373,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);
>> @@ -386,12 +386,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);
>>
>> --
>
> This clashes with
>
> https://lore.kernel.org/linux-pm/1758256.QkHrqEjB74@rjwysocki.net/
>
> which I would prefer to go in first if you don't mind.
My other patchset which fixes bugs here, could go in before:
https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/
so it will be backported. Other than that, I am fine with rebasing my
changes. There is no point in refactoring the code if it is being
removed/reshuffled :)
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop
2024-08-16 12:21 ` Krzysztof Kozlowski
@ 2024-08-16 16:02 ` Rafael J. Wysocki
0 siblings, 0 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2024-08-16 16:02 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, Chen-Yu Tsai
On Fri, Aug 16, 2024 at 2:22 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 16/08/2024 13:30, Rafael J. Wysocki wrote:
> > On Fri, Aug 16, 2024 at 9:40 AM Krzysztof Kozlowski
> > <krzysztof.kozlowski@linaro.org> wrote:
> >>
> >> Use scoped for_each_child_of_node_scoped() when iterating over device
> >> nodes to make code a bit simpler.
> >>
> >> Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
> >> 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 94cc077ab3a1..ce398fde48bb 100644
> >> --- a/drivers/thermal/thermal_of.c
> >> +++ b/drivers/thermal/thermal_of.c
> >> @@ -373,7 +373,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);
> >> @@ -386,12 +386,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);
> >>
> >> --
> >
> > This clashes with
> >
> > https://lore.kernel.org/linux-pm/1758256.QkHrqEjB74@rjwysocki.net/
> >
> > which I would prefer to go in first if you don't mind.
>
> My other patchset which fixes bugs here, could go in before:
> https://lore.kernel.org/all/20240814195823.437597-1-krzysztof.kozlowski@linaro.org/
Right, but these don't clash significantly if I'm not mistaken.
It may make sense to push them for 6.11-rc even.
> so it will be backported. Other than that, I am fine with rebasing my
> changes. There is no point in refactoring the code if it is being
> removed/reshuffled :)
OK
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-08-16 16:02 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-16 7:40 [PATCH v2 0/7] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 1/7] thermal: of: Use scoped device node handling to simplify of_find_trip_id() Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 2/7] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 3/7] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 4/7] thermal: of: Simplify thermal_of_for_each_cooling_maps() with scoped for each OF child loop Krzysztof Kozlowski
2024-08-16 11:30 ` Rafael J. Wysocki
2024-08-16 12:21 ` Krzysztof Kozlowski
2024-08-16 16:02 ` Rafael J. Wysocki
2024-08-16 7:40 ` [PATCH v2 5/7] thermal: qcom-spmi-adc-tm5: Simplify " Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 6/7] thermal: tegra: " Krzysztof Kozlowski
2024-08-16 7:40 ` [PATCH v2 7/7] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox