* [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop
@ 2024-08-16 15:09 Krzysztof Kozlowski
2024-08-16 15:09 ` [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
` (4 more replies)
0 siblings, 5 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 15:09 UTC (permalink / raw)
To: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
Cc: 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/cpuidle/cpuidle-psci-domain.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
index ea28b73ef3fb..146f97068022 100644
--- a/drivers/cpuidle/cpuidle-psci-domain.c
+++ b/drivers/cpuidle/cpuidle-psci-domain.c
@@ -142,7 +142,6 @@ static const struct of_device_id psci_of_match[] = {
static int psci_cpuidle_domain_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
- struct device_node *node;
bool use_osi = psci_has_osi_support();
int ret = 0, pd_count = 0;
@@ -153,15 +152,13 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
* Parse child nodes for the "#power-domain-cells" property and
* initialize a genpd/genpd-of-provider pair when it's found.
*/
- for_each_child_of_node(np, node) {
+ for_each_child_of_node_scoped(np, node) {
if (!of_property_present(node, "#power-domain-cells"))
continue;
ret = psci_pd_init(node, use_osi);
- if (ret) {
- of_node_put(node);
+ if (ret)
goto exit;
- }
pd_count++;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths
2024-08-16 15:09 [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 15:09 ` Krzysztof Kozlowski
2024-08-19 16:13 ` Jonathan Cameron
2024-08-16 15:09 ` [PATCH 3/4] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop Krzysztof Kozlowski
` (3 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 15:09 UTC (permalink / raw)
To: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
Cc: 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/cpuidle/cpuidle-riscv-sbi.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index a6e123dfe394..5bb3401220d2 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -8,6 +8,7 @@
#define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
+#include <linux/cleanup.h>
#include <linux/cpuhotplug.h>
#include <linux/cpuidle.h>
#include <linux/cpumask.h>
@@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
{
struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu);
struct device_node *state_node;
- struct device_node *cpu_node;
u32 *states;
int i, ret;
- cpu_node = of_cpu_device_node_get(cpu);
+ struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu);
if (!cpu_node)
return -ENODEV;
states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL);
- if (!states) {
- ret = -ENOMEM;
- goto fail;
- }
+ if (!states)
+ return -ENOMEM;
/* Parse SBI specific details from state DT nodes */
for (i = 1; i < state_count; i++) {
@@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
pr_debug("sbi-state %#x index %d\n", states[i], i);
}
- if (i != state_count) {
- ret = -ENODEV;
- goto fail;
- }
+ if (i != state_count)
+ return -ENODEV;
/* Initialize optional data, used for the hierarchical topology. */
ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu);
@@ -277,10 +273,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
/* Store states in the per-cpu struct. */
data->states = states;
-fail:
- of_node_put(cpu_node);
-
- return ret;
+ return 0;
}
static void sbi_cpuidle_deinit_cpu(int cpu)
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/4] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop
2024-08-16 15:09 [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-16 15:09 ` [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-16 15:09 ` Krzysztof Kozlowski
2024-08-19 16:24 ` Jonathan Cameron
2024-08-16 15:09 ` [PATCH 4/4] cpuidle: dt_idle_genpd: " Krzysztof Kozlowski
` (2 subsequent siblings)
4 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 15:09 UTC (permalink / raw)
To: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
Cc: 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/cpuidle/cpuidle-riscv-sbi.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index 5bb3401220d2..d228b4d18d56 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -448,7 +448,6 @@ static void sbi_pd_remove(void)
static int sbi_genpd_probe(struct device_node *np)
{
- struct device_node *node;
int ret = 0, pd_count = 0;
if (!np)
@@ -458,13 +457,13 @@ static int sbi_genpd_probe(struct device_node *np)
* Parse child nodes for the "#power-domain-cells" property and
* initialize a genpd/genpd-of-provider pair when it's found.
*/
- for_each_child_of_node(np, node) {
+ for_each_child_of_node_scoped(np, node) {
if (!of_property_present(node, "#power-domain-cells"))
continue;
ret = sbi_pd_init(node);
if (ret)
- goto put_node;
+ goto remove_pd;
pd_count++;
}
@@ -480,8 +479,6 @@ static int sbi_genpd_probe(struct device_node *np)
return 0;
-put_node:
- of_node_put(node);
remove_pd:
sbi_pd_remove();
pr_err("failed to create CPU PM domains ret=%d\n", ret);
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/4] cpuidle: dt_idle_genpd: Simplify with scoped for each OF child loop
2024-08-16 15:09 [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-16 15:09 ` [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-08-16 15:09 ` [PATCH 3/4] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-16 15:09 ` Krzysztof Kozlowski
2024-08-19 16:26 ` Jonathan Cameron
2024-08-20 9:34 ` Ulf Hansson
2024-08-19 16:11 ` [PATCH 1/4] cpuidle: psci: " Jonathan Cameron
2024-08-20 9:33 ` Ulf Hansson
4 siblings, 2 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-16 15:09 UTC (permalink / raw)
To: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
Cc: 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/cpuidle/dt_idle_genpd.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/cpuidle/dt_idle_genpd.c b/drivers/cpuidle/dt_idle_genpd.c
index 1af63c189039..203e9b754aea 100644
--- a/drivers/cpuidle/dt_idle_genpd.c
+++ b/drivers/cpuidle/dt_idle_genpd.c
@@ -130,11 +130,10 @@ struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np,
int dt_idle_pd_init_topology(struct device_node *np)
{
- struct device_node *node;
struct of_phandle_args child, parent;
int ret;
- for_each_child_of_node(np, node) {
+ for_each_child_of_node_scoped(np, node) {
if (of_parse_phandle_with_args(node, "power-domains",
"#power-domain-cells", 0, &parent))
continue;
@@ -143,10 +142,8 @@ int dt_idle_pd_init_topology(struct device_node *np)
child.args_count = 0;
ret = of_genpd_add_subdomain(&parent, &child);
of_node_put(parent.np);
- if (ret) {
- of_node_put(node);
+ if (ret)
return ret;
- }
}
return 0;
@@ -154,11 +151,10 @@ int dt_idle_pd_init_topology(struct device_node *np)
int dt_idle_pd_remove_topology(struct device_node *np)
{
- struct device_node *node;
struct of_phandle_args child, parent;
int ret;
- for_each_child_of_node(np, node) {
+ for_each_child_of_node_scoped(np, node) {
if (of_parse_phandle_with_args(node, "power-domains",
"#power-domain-cells", 0, &parent))
continue;
@@ -167,10 +163,8 @@ int dt_idle_pd_remove_topology(struct device_node *np)
child.args_count = 0;
ret = of_genpd_remove_subdomain(&parent, &child);
of_node_put(parent.np);
- if (ret) {
- of_node_put(node);
+ if (ret)
return ret;
- }
}
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop
2024-08-16 15:09 [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop Krzysztof Kozlowski
` (2 preceding siblings ...)
2024-08-16 15:09 ` [PATCH 4/4] cpuidle: dt_idle_genpd: " Krzysztof Kozlowski
@ 2024-08-19 16:11 ` Jonathan Cameron
2024-08-20 9:33 ` Ulf Hansson
4 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:11 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On Fri, 16 Aug 2024 17:09:28 +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>
Looks fine,
FWIW
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
If you are bored, the pr_err() at end of here seems like it should be
return dev_err_probe(pdev->dev, ret, "failed to create CPU PM domains\n");
But that's obviously completely unrelated!
> ---
> drivers/cpuidle/cpuidle-psci-domain.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
> index ea28b73ef3fb..146f97068022 100644
> --- a/drivers/cpuidle/cpuidle-psci-domain.c
> +++ b/drivers/cpuidle/cpuidle-psci-domain.c
> @@ -142,7 +142,6 @@ static const struct of_device_id psci_of_match[] = {
> static int psci_cpuidle_domain_probe(struct platform_device *pdev)
> {
> struct device_node *np = pdev->dev.of_node;
> - struct device_node *node;
> bool use_osi = psci_has_osi_support();
> int ret = 0, pd_count = 0;
>
> @@ -153,15 +152,13 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
> * Parse child nodes for the "#power-domain-cells" property and
> * initialize a genpd/genpd-of-provider pair when it's found.
> */
> - for_each_child_of_node(np, node) {
> + for_each_child_of_node_scoped(np, node) {
> if (!of_property_present(node, "#power-domain-cells"))
> continue;
>
> ret = psci_pd_init(node, use_osi);
> - if (ret) {
> - of_node_put(node);
> + if (ret)
> goto exit;
> - }
>
> pd_count++;
> }
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths
2024-08-16 15:09 ` [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-19 16:13 ` Jonathan Cameron
2024-08-19 16:19 ` Jonathan Cameron
2024-08-20 9:29 ` Krzysztof Kozlowski
0 siblings, 2 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:13 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On Fri, 16 Aug 2024 17:09:29 +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.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
The original code looks suspect. See below.
> ---
> drivers/cpuidle/cpuidle-riscv-sbi.c | 21 +++++++--------------
> 1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> index a6e123dfe394..5bb3401220d2 100644
> --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> @@ -8,6 +8,7 @@
>
> #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
>
> +#include <linux/cleanup.h>
> #include <linux/cpuhotplug.h>
> #include <linux/cpuidle.h>
> #include <linux/cpumask.h>
> @@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
> {
> struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu);
> struct device_node *state_node;
> - struct device_node *cpu_node;
> u32 *states;
> int i, ret;
>
> - cpu_node = of_cpu_device_node_get(cpu);
> + struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu);
> if (!cpu_node)
> return -ENODEV;
>
> states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL);
> - if (!states) {
> - ret = -ENOMEM;
> - goto fail;
> - }
> + if (!states)
> + return -ENOMEM;
>
> /* Parse SBI specific details from state DT nodes */
> for (i = 1; i < state_count; i++) {
> @@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
>
> pr_debug("sbi-state %#x index %d\n", states[i], i);
> }
> - if (i != state_count) {
> - ret = -ENODEV;
> - goto fail;
> - }
> + if (i != state_count)
> + return -ENODEV;
>
> /* Initialize optional data, used for the hierarchical topology. */
> ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu);
The handling of error ret from here doesn't free the node.
Bug or something subtle I'm missing?
If it's a bug, then fixes tag.
> @@ -277,10 +273,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
> /* Store states in the per-cpu struct. */
> data->states = states;
>
> -fail:
> - of_node_put(cpu_node);
> -
> - return ret;
> + return 0;
> }
>
> static void sbi_cpuidle_deinit_cpu(int cpu)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths
2024-08-19 16:13 ` Jonathan Cameron
@ 2024-08-19 16:19 ` Jonathan Cameron
2024-08-20 9:36 ` Krzysztof Kozlowski
2024-08-20 9:29 ` Krzysztof Kozlowski
1 sibling, 1 reply; 14+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:19 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On Mon, 19 Aug 2024 17:13:13 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:
> On Fri, 16 Aug 2024 17:09:29 +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.
> >
> > Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> The original code looks suspect. See below.
Whilst here... Why not do similar for state_node to avoid
the delayed return check.
Existing code
{
state_node = of_get_cpu_state_node(cpu_node, i - 1);
if (!state_node)
break;
ret = sbi_dt_parse_state_node(state_node, &states[i]);
of_node_put(state_node);
if (ret)
//another bug here on holding cpu_node btw.
return ret;
pr_debug("sbi-state %#x index %d\n", states[i], i);
}
//I think only path to this is is early break above.
if (i != state_count) {
ret = -ENODEV;
goto fail;
}
Can be something like
{
struct device_node *state_node __free(device_node) =
= of_get-cpu_State_nod(cpu_node, i - 1);
if (!state_node)
return -ENODEV;
ret = sbi_dt_parse_state_node(state_node, &states[i]);
if (ret)
return ret;
pr_debug("sbi-state %#x index %d\n", states[i], i);
}
>
> > ---
> > drivers/cpuidle/cpuidle-riscv-sbi.c | 21 +++++++--------------
> > 1 file changed, 7 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> > index a6e123dfe394..5bb3401220d2 100644
> > --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> > +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> > @@ -8,6 +8,7 @@
> >
> > #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
> >
> > +#include <linux/cleanup.h>
> > #include <linux/cpuhotplug.h>
> > #include <linux/cpuidle.h>
> > #include <linux/cpumask.h>
> > @@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
> > {
> > struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu);
> > struct device_node *state_node;
> > - struct device_node *cpu_node;
> > u32 *states;
> > int i, ret;
> >
> > - cpu_node = of_cpu_device_node_get(cpu);
> > + struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu);
> > if (!cpu_node)
> > return -ENODEV;
> >
> > states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL);
> > - if (!states) {
> > - ret = -ENOMEM;
> > - goto fail;
> > - }
> > + if (!states)
> > + return -ENOMEM;
> >
> > /* Parse SBI specific details from state DT nodes */
> > for (i = 1; i < state_count; i++) {
> > @@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
> >
> > pr_debug("sbi-state %#x index %d\n", states[i], i);
> > }
> > - if (i != state_count) {
> > - ret = -ENODEV;
> > - goto fail;
> > - }
> > + if (i != state_count)
> > + return -ENODEV;
> >
> > /* Initialize optional data, used for the hierarchical topology. */
> > ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu);
> The handling of error ret from here doesn't free the node.
>
> Bug or something subtle I'm missing?
>
> If it's a bug, then fixes tag.
>
>
> > @@ -277,10 +273,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
> > /* Store states in the per-cpu struct. */
> > data->states = states;
> >
> > -fail:
> > - of_node_put(cpu_node);
> > -
> > - return ret;
> > + return 0;
> > }
> >
> > static void sbi_cpuidle_deinit_cpu(int cpu)
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/4] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop
2024-08-16 15:09 ` [PATCH 3/4] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-19 16:24 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:24 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On Fri, 16 Aug 2024 17:09:30 +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>
I don't much like the no_pd: label that does nothing useful, but
unrelated to this.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4] cpuidle: dt_idle_genpd: Simplify with scoped for each OF child loop
2024-08-16 15:09 ` [PATCH 4/4] cpuidle: dt_idle_genpd: " Krzysztof Kozlowski
@ 2024-08-19 16:26 ` Jonathan Cameron
2024-08-20 9:34 ` Ulf Hansson
1 sibling, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-08-19 16:26 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On Fri, 16 Aug 2024 17:09:31 +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>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths
2024-08-19 16:13 ` Jonathan Cameron
2024-08-19 16:19 ` Jonathan Cameron
@ 2024-08-20 9:29 ` Krzysztof Kozlowski
1 sibling, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-20 9:29 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On 19/08/2024 18:13, Jonathan Cameron wrote:
>>
>> /* Parse SBI specific details from state DT nodes */
>> for (i = 1; i < state_count; i++) {
>> @@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
>>
>> pr_debug("sbi-state %#x index %d\n", states[i], i);
>> }
>> - if (i != state_count) {
>> - ret = -ENODEV;
>> - goto fail;
>> - }
>> + if (i != state_count)
>> + return -ENODEV;
>>
>> /* Initialize optional data, used for the hierarchical topology. */
>> ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu);
> The handling of error ret from here doesn't free the node.
>
> Bug or something subtle I'm missing?
>
> If it's a bug, then fixes tag.
Yeah, indeed it is a fix.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop
2024-08-16 15:09 [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop Krzysztof Kozlowski
` (3 preceding siblings ...)
2024-08-19 16:11 ` [PATCH 1/4] cpuidle: psci: " Jonathan Cameron
@ 2024-08-20 9:33 ` Ulf Hansson
4 siblings, 0 replies; 14+ messages in thread
From: Ulf Hansson @ 2024-08-20 9:33 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rafael J. Wysocki, Daniel Lezcano, Anup Patel, Paul Walmsley,
Palmer Dabbelt, Albert Ou, linux-pm, linux-arm-kernel,
linux-kernel, linux-riscv
On Fri, 16 Aug 2024 at 17:09, 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>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/cpuidle/cpuidle-psci-domain.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
> index ea28b73ef3fb..146f97068022 100644
> --- a/drivers/cpuidle/cpuidle-psci-domain.c
> +++ b/drivers/cpuidle/cpuidle-psci-domain.c
> @@ -142,7 +142,6 @@ static const struct of_device_id psci_of_match[] = {
> static int psci_cpuidle_domain_probe(struct platform_device *pdev)
> {
> struct device_node *np = pdev->dev.of_node;
> - struct device_node *node;
> bool use_osi = psci_has_osi_support();
> int ret = 0, pd_count = 0;
>
> @@ -153,15 +152,13 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
> * Parse child nodes for the "#power-domain-cells" property and
> * initialize a genpd/genpd-of-provider pair when it's found.
> */
> - for_each_child_of_node(np, node) {
> + for_each_child_of_node_scoped(np, node) {
> if (!of_property_present(node, "#power-domain-cells"))
> continue;
>
> ret = psci_pd_init(node, use_osi);
> - if (ret) {
> - of_node_put(node);
> + if (ret)
> goto exit;
> - }
>
> pd_count++;
> }
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4] cpuidle: dt_idle_genpd: Simplify with scoped for each OF child loop
2024-08-16 15:09 ` [PATCH 4/4] cpuidle: dt_idle_genpd: " Krzysztof Kozlowski
2024-08-19 16:26 ` Jonathan Cameron
@ 2024-08-20 9:34 ` Ulf Hansson
1 sibling, 0 replies; 14+ messages in thread
From: Ulf Hansson @ 2024-08-20 9:34 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rafael J. Wysocki, Daniel Lezcano, Anup Patel, Paul Walmsley,
Palmer Dabbelt, Albert Ou, linux-pm, linux-arm-kernel,
linux-kernel, linux-riscv
On Fri, 16 Aug 2024 at 17:09, 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>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/cpuidle/dt_idle_genpd.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/cpuidle/dt_idle_genpd.c b/drivers/cpuidle/dt_idle_genpd.c
> index 1af63c189039..203e9b754aea 100644
> --- a/drivers/cpuidle/dt_idle_genpd.c
> +++ b/drivers/cpuidle/dt_idle_genpd.c
> @@ -130,11 +130,10 @@ struct generic_pm_domain *dt_idle_pd_alloc(struct device_node *np,
>
> int dt_idle_pd_init_topology(struct device_node *np)
> {
> - struct device_node *node;
> struct of_phandle_args child, parent;
> int ret;
>
> - for_each_child_of_node(np, node) {
> + for_each_child_of_node_scoped(np, node) {
> if (of_parse_phandle_with_args(node, "power-domains",
> "#power-domain-cells", 0, &parent))
> continue;
> @@ -143,10 +142,8 @@ int dt_idle_pd_init_topology(struct device_node *np)
> child.args_count = 0;
> ret = of_genpd_add_subdomain(&parent, &child);
> of_node_put(parent.np);
> - if (ret) {
> - of_node_put(node);
> + if (ret)
> return ret;
> - }
> }
>
> return 0;
> @@ -154,11 +151,10 @@ int dt_idle_pd_init_topology(struct device_node *np)
>
> int dt_idle_pd_remove_topology(struct device_node *np)
> {
> - struct device_node *node;
> struct of_phandle_args child, parent;
> int ret;
>
> - for_each_child_of_node(np, node) {
> + for_each_child_of_node_scoped(np, node) {
> if (of_parse_phandle_with_args(node, "power-domains",
> "#power-domain-cells", 0, &parent))
> continue;
> @@ -167,10 +163,8 @@ int dt_idle_pd_remove_topology(struct device_node *np)
> child.args_count = 0;
> ret = of_genpd_remove_subdomain(&parent, &child);
> of_node_put(parent.np);
> - if (ret) {
> - of_node_put(node);
> + if (ret)
> return ret;
> - }
> }
>
> return 0;
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths
2024-08-19 16:19 ` Jonathan Cameron
@ 2024-08-20 9:36 ` Krzysztof Kozlowski
2024-08-21 11:48 ` Jonathan Cameron
0 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-20 9:36 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On 19/08/2024 18:19, Jonathan Cameron wrote:
> On Mon, 19 Aug 2024 17:13:13 +0100
> Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:
>
>> On Fri, 16 Aug 2024 17:09:29 +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.
>>>
>>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> The original code looks suspect. See below.
>
> Whilst here... Why not do similar for state_node to avoid
> the delayed return check.
> Existing code
> {
> state_node = of_get_cpu_state_node(cpu_node, i - 1);
> if (!state_node)
> break;
I don't see how __free() helps here. You can return regardless of __free().
>
> ret = sbi_dt_parse_state_node(state_node, &states[i]);
> of_node_put(state_node);
... and this code is quite easy to read: you get reference and
immediately release it.
>
> if (ret)
> //another bug here on holding cpu_node btw.
> return ret;
> pr_debug("sbi-state %#x index %d\n", states[i], i);
> }
> //I think only path to this is is early break above.
> if (i != state_count) {
> ret = -ENODEV;
> goto fail;
> }
> Can be something like
>
> {
> struct device_node *state_node __free(device_node) =
> = of_get-cpu_State_nod(cpu_node, i - 1);
>
> if (!state_node)
> return -ENODEV;
>
> ret = sbi_dt_parse_state_node(state_node, &states[i]);
> if (ret)
> return ret;
>
> pr_debug("sbi-state %#x index %d\n", states[i], i);
> }
>
Maybe I miss something, but I do not see how the __free() simplifies
here anything.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths
2024-08-20 9:36 ` Krzysztof Kozlowski
@ 2024-08-21 11:48 ` Jonathan Cameron
0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2024-08-21 11:48 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Ulf Hansson, Rafael J. Wysocki, Daniel Lezcano, Anup Patel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-pm,
linux-arm-kernel, linux-kernel, linux-riscv
On Tue, 20 Aug 2024 11:36:32 +0200
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> On 19/08/2024 18:19, Jonathan Cameron wrote:
> > On Mon, 19 Aug 2024 17:13:13 +0100
> > Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:
> >
> >> On Fri, 16 Aug 2024 17:09:29 +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.
> >>>
> >>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >> The original code looks suspect. See below.
> >
> > Whilst here... Why not do similar for state_node to avoid
> > the delayed return check.
> > Existing code
> > {
> > state_node = of_get_cpu_state_node(cpu_node, i - 1);
> > if (!state_node)
> > break;
>
> I don't see how __free() helps here. You can return regardless of __free().
>
> >
> > ret = sbi_dt_parse_state_node(state_node, &states[i]);
> > of_node_put(state_node);
>
> ... and this code is quite easy to read: you get reference and
> immediately release it.
>
> >
> > if (ret)
> > //another bug here on holding cpu_node btw.
> > return ret;
> > pr_debug("sbi-state %#x index %d\n", states[i], i);
> > }
> > //I think only path to this is is early break above.
> > if (i != state_count) {
> > ret = -ENODEV;
> > goto fail;
> > }
> > Can be something like
> >
> > {
> > struct device_node *state_node __free(device_node) =
> > = of_get-cpu_State_nod(cpu_node, i - 1);
> >
> > if (!state_node)
> > return -ENODEV;
> >
> > ret = sbi_dt_parse_state_node(state_node, &states[i]);
> > if (ret)
> > return ret;
> >
> > pr_debug("sbi-state %#x index %d\n", states[i], i);
> > }
> >
>
> Maybe I miss something, but I do not see how the __free() simplifies
> here anything.
Personal preference. To my eyes, it does, but indeed not a huge
advantage.
Jonathan
>
> Best regards,
> Krzysztof
>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-08-21 11:49 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-16 15:09 [PATCH 1/4] cpuidle: psci: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-16 15:09 ` [PATCH 2/4] cpuidle: riscv-sbi: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
2024-08-19 16:13 ` Jonathan Cameron
2024-08-19 16:19 ` Jonathan Cameron
2024-08-20 9:36 ` Krzysztof Kozlowski
2024-08-21 11:48 ` Jonathan Cameron
2024-08-20 9:29 ` Krzysztof Kozlowski
2024-08-16 15:09 ` [PATCH 3/4] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-19 16:24 ` Jonathan Cameron
2024-08-16 15:09 ` [PATCH 4/4] cpuidle: dt_idle_genpd: " Krzysztof Kozlowski
2024-08-19 16:26 ` Jonathan Cameron
2024-08-20 9:34 ` Ulf Hansson
2024-08-19 16:11 ` [PATCH 1/4] cpuidle: psci: " Jonathan Cameron
2024-08-20 9:33 ` Ulf Hansson
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).