[PATCH 2/2] cpuidle: riscv-sbi: use cleanup attribute for np in for_each_possible_cpu

Javier Carrasco posted 2 patches 3 weeks, 4 days ago
There is a newer version of this series
[PATCH 2/2] cpuidle: riscv-sbi: use cleanup attribute for np in for_each_possible_cpu
Posted by Javier Carrasco 3 weeks, 4 days ago
Simplify the code and make it more robust against new execution paths in
the loop by means of the cleanup attribute.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/cpuidle/cpuidle-riscv-sbi.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index 2b3aec09b895..3a78d6b7598b 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -504,23 +504,21 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
 	int cpu, ret;
 	struct cpuidle_driver *drv;
 	struct cpuidle_device *dev;
-	struct device_node *np, *pds_node;
+	struct device_node *pds_node;
 
 	/* Detect OSI support based on CPU DT nodes */
 	sbi_cpuidle_use_osi = true;
 	for_each_possible_cpu(cpu) {
-		np = of_cpu_device_node_get(cpu);
+		struct device_node *np __free(device_node) =
+			of_cpu_device_node_get(cpu);
 		if (np &&
 		    of_property_present(np, "power-domains") &&
 		    of_property_present(np, "power-domain-names")) {
-			of_node_put(np);
 			continue;
 		} else {
 			sbi_cpuidle_use_osi = false;
-			of_node_put(np);
 			break;
 		}
-		of_node_put(np);
 	}
 
 	/* Populate generic power domains from DT nodes */

-- 
2.43.0
Re: [PATCH 2/2] cpuidle: riscv-sbi: use cleanup attribute for np in for_each_possible_cpu
Posted by Krzysztof Kozlowski 3 weeks, 3 days ago
On 30/10/2024 07:44, Javier Carrasco wrote:
> Simplify the code and make it more robust against new execution paths in
> the loop by means of the cleanup attribute.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
>  drivers/cpuidle/cpuidle-riscv-sbi.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> index 2b3aec09b895..3a78d6b7598b 100644
> --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> @@ -504,23 +504,21 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
>  	int cpu, ret;
>  	struct cpuidle_driver *drv;
>  	struct cpuidle_device *dev;
> -	struct device_node *np, *pds_node;
> +	struct device_node *pds_node;
>  
>  	/* Detect OSI support based on CPU DT nodes */
>  	sbi_cpuidle_use_osi = true;
>  	for_each_possible_cpu(cpu) {
> -		np = of_cpu_device_node_get(cpu);
> +		struct device_node *np __free(device_node) =
> +			of_cpu_device_node_get(cpu);
>  		if (np &&
>  		    of_property_present(np, "power-domains") &&
>  		    of_property_present(np, "power-domain-names")) {
> -			of_node_put(np);

You just added this. Don't add code which is immediately removed. It's a
noop or wrong code.

If you want to backport something: send a backport. We work here on
mainline and in mainline this is one logical change: fixing issue.
Whether you fix issue with of_node_put or cleanup or by removing this
code entirely, it does not matter. All of these are fixing the same, one
issue. This is inflating mainline history with unnecessary commits.



Best regards,
Krzysztof