* [PATCH v3 1/6] thermal: of: Simplify thermal_of_should_bind with scoped for each OF child
2024-10-08 9:00 [PATCH v3 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
@ 2024-10-08 9:00 ` Krzysztof Kozlowski
2024-10-08 11:28 ` Jonathan Cameron
2024-10-08 9:00 ` [PATCH v3 2/6] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
` (4 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-08 9:00 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>
---
Changes in v3:
1. New patch
---
drivers/thermal/thermal_of.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index a4caf7899f8e4a5f3422e4c02c66502b5050fd6d..f0ffc0e335ba9406f4fd858d6c561f9d23f4b842 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -301,7 +301,7 @@ static bool thermal_of_should_bind(struct thermal_zone_device *tz,
struct thermal_cooling_device *cdev,
struct cooling_spec *c)
{
- struct device_node *tz_np, *cm_np, *child;
+ struct device_node *tz_np, *cm_np;
bool result = false;
tz_np = thermal_of_zone_get_by_name(tz);
@@ -315,7 +315,7 @@ static bool thermal_of_should_bind(struct thermal_zone_device *tz,
goto out;
/* Look up the trip and the cdev in the cooling maps. */
- for_each_child_of_node(cm_np, child) {
+ for_each_child_of_node_scoped(cm_np, child) {
struct device_node *tr_np;
int count, i;
@@ -334,7 +334,6 @@ static bool thermal_of_should_bind(struct thermal_zone_device *tz,
break;
}
- of_node_put(child);
break;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v3 1/6] thermal: of: Simplify thermal_of_should_bind with scoped for each OF child
2024-10-08 9:00 ` [PATCH v3 1/6] thermal: of: Simplify thermal_of_should_bind with scoped for each OF child Krzysztof Kozlowski
@ 2024-10-08 11:28 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-10-08 11:28 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 Tue, 08 Oct 2024 11:00:01 +0200
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.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 2/6] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
2024-10-08 9:00 [PATCH v3 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-10-08 9:00 ` [PATCH v3 1/6] thermal: of: Simplify thermal_of_should_bind with scoped for each OF child Krzysztof Kozlowski
@ 2024-10-08 9:00 ` Krzysztof Kozlowski
2024-10-08 11:32 ` Jonathan Cameron
2024-10-08 9:00 ` [PATCH v3 3/6] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
` (3 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-08 9:00 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 f0ffc0e335ba9406f4fd858d6c561f9d23f4b842..d7d6f62caa13d545e5f7fae4c8ac1e737bf4c4b1 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -96,10 +96,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);
@@ -108,15 +107,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;
@@ -127,15 +123,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] 14+ messages in thread* Re: [PATCH v3 2/6] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
2024-10-08 9:00 ` [PATCH v3 2/6] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
@ 2024-10-08 11:32 ` Jonathan Cameron
2024-10-10 17:53 ` Krzysztof Kozlowski
0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Cameron @ 2024-10-08 11:32 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 Tue, 08 Oct 2024 11:00:02 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> 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>
A follow up suggestion below.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> ---
>
> 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 f0ffc0e335ba9406f4fd858d6c561f9d23f4b842..d7d6f62caa13d545e5f7fae4c8ac1e737bf4c4b1 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -96,10 +96,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);
> @@ -108,15 +107,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;
>
> @@ -127,15 +123,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);
May be worth a follow up to do __free(kfree) on this + a steal for the return.
Then push the ntrips set until after the populate so it doesn't need resetting to 0.
> *ntrips = 0;
> -out_of_node_put:
> - of_node_put(trips);
>
> return ERR_PTR(ret);
> }
>
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v3 2/6] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init()
2024-10-08 11:32 ` Jonathan Cameron
@ 2024-10-10 17:53 ` Krzysztof Kozlowski
0 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-10 17:53 UTC (permalink / raw)
To: Jonathan Cameron
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 08/10/2024 13:32, Jonathan Cameron 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;
>>
>> @@ -127,15 +123,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);
> May be worth a follow up to do __free(kfree) on this + a steal for the return.
> Then push the ntrips set until after the populate so it doesn't need resetting to 0.
That's good idea, I'll send v4 with a revised patch (dropping your RB here).
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 3/6] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
2024-10-08 9:00 [PATCH v3 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
2024-10-08 9:00 ` [PATCH v3 1/6] thermal: of: Simplify thermal_of_should_bind with scoped for each OF child Krzysztof Kozlowski
2024-10-08 9:00 ` [PATCH v3 2/6] thermal: of: Use scoped device node handling to simplify thermal_of_trips_init() Krzysztof Kozlowski
@ 2024-10-08 9:00 ` Krzysztof Kozlowski
2024-10-08 12:21 ` Jonathan Cameron
2024-10-08 9:00 ` [PATCH v3 4/6] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop Krzysztof Kozlowski
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-08 9:00 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/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 d7d6f62caa13d545e5f7fae4c8ac1e737bf4c4b1..a2e20986668b7aa465f3f2ab861f70101d2111c8 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -134,10 +134,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);
@@ -155,8 +154,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++) {
@@ -168,22 +166,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] 14+ messages in thread* Re: [PATCH v3 3/6] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find()
2024-10-08 9:00 ` [PATCH v3 3/6] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
@ 2024-10-08 12:21 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-10-08 12:21 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 Tue, 08 Oct 2024 11:00:03 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> 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>
Ah. I was wondering why you didn't do this in patch 1.
Sensible to split though I'd have put it as patch 2 for the lazy reviewer
to spot more easily ;)
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 4/6] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop
2024-10-08 9:00 [PATCH v3 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (2 preceding siblings ...)
2024-10-08 9:00 ` [PATCH v3 3/6] thermal: of: Use scoped device node handling to simplify of_thermal_zone_find() Krzysztof Kozlowski
@ 2024-10-08 9:00 ` Krzysztof Kozlowski
2024-10-08 12:23 ` Jonathan Cameron
2024-10-08 9:00 ` [PATCH v3 5/6] thermal: tegra: " Krzysztof Kozlowski
2024-10-08 9:00 ` [PATCH v3 6/6] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
5 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-08 9:00 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 5e94a45eba3eef65e436a01b3aa58aabf5f706c2..d7f2e6ca92c2c9fb532ca5d4bcc22b6c2cddbdb0 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] 14+ messages in thread* Re: [PATCH v3 4/6] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop
2024-10-08 9:00 ` [PATCH v3 4/6] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-10-08 12:23 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-10-08 12:23 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 Tue, 08 Oct 2024 11:00:04 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> 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>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 5/6] thermal: tegra: Simplify with scoped for each OF child loop
2024-10-08 9:00 [PATCH v3 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (3 preceding siblings ...)
2024-10-08 9:00 ` [PATCH v3 4/6] thermal: qcom-spmi-adc-tm5: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-10-08 9:00 ` Krzysztof Kozlowski
2024-10-08 12:24 ` Jonathan Cameron
2024-10-08 9:00 ` [PATCH v3 6/6] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
5 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-08 9:00 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 a023c948afbddd6d9fc1a00b2fe310c71147bda9..ff4eedb553fb6e78c94b714dd179193c244b6589 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] 14+ messages in thread* Re: [PATCH v3 5/6] thermal: tegra: Simplify with scoped for each OF child loop
2024-10-08 9:00 ` [PATCH v3 5/6] thermal: tegra: " Krzysztof Kozlowski
@ 2024-10-08 12:24 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-10-08 12:24 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 Tue, 08 Oct 2024 11:00:05 +0200
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>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 6/6] thermal: sun8i: Use scoped device node handling to simplify error paths
2024-10-08 9:00 [PATCH v3 0/6] thermal: scope/cleanup.h improvements Krzysztof Kozlowski
` (4 preceding siblings ...)
2024-10-08 9:00 ` [PATCH v3 5/6] thermal: tegra: " Krzysztof Kozlowski
@ 2024-10-08 9:00 ` Krzysztof Kozlowski
2024-10-08 12:26 ` Jonathan Cameron
5 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-08 9:00 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 3203d8bd13a8fc2a9e5a59b3547cefc2440542c6..22674790629a7b549d1ce618998ff51f6553613e 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] 14+ messages in thread* Re: [PATCH v3 6/6] thermal: sun8i: Use scoped device node handling to simplify error paths
2024-10-08 9:00 ` [PATCH v3 6/6] thermal: sun8i: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-10-08 12:26 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-10-08 12:26 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 Tue, 08 Oct 2024 11:00:06 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> 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>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
I wonder if we will eventually get to the point where we might as well
use the scoped case for the few remaining instances where there
is no early exit and then end up dropping the unscoped one.
I guess we'll see. Keep up the good work dealing with all these!
Jonathan
^ permalink raw reply [flat|nested] 14+ messages in thread