Skip to content

Commit 7e25044

Browse files
javiercarrascocruzpalmer-dabbelt
authored andcommitted
cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu
The 'np' device_node is initialized via of_cpu_device_node_get(), which requires explicit calls to of_node_put() when it is no longer required to avoid leaking the resource. Instead of adding the missing calls to of_node_put() in all execution paths, use the cleanup attribute for 'np' by means of the __free() macro, which automatically calls of_node_put() when the variable goes out of scope. Given that 'np' is only used within the for_each_possible_cpu(), reduce its scope to release the nood after every iteration of the loop. Fixes: 6abf32f ("cpuidle: Add RISC-V SBI CPU idle driver") Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 13134cc commit 7e25044

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/cpuidle/cpuidle-riscv-sbi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,12 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
504504
int cpu, ret;
505505
struct cpuidle_driver *drv;
506506
struct cpuidle_device *dev;
507-
struct device_node *np, *pds_node;
507+
struct device_node *pds_node;
508508

509509
/* Detect OSI support based on CPU DT nodes */
510510
sbi_cpuidle_use_osi = true;
511511
for_each_possible_cpu(cpu) {
512-
np = of_cpu_device_node_get(cpu);
512+
struct device_node *np __free(device_node) = of_cpu_device_node_get(cpu);
513513
if (np &&
514514
of_property_present(np, "power-domains") &&
515515
of_property_present(np, "power-domain-names")) {

0 commit comments

Comments
 (0)