Skip to content

Commit a309320

Browse files
krzkrafaeljw
authored andcommitted
cpuidle: riscv-sbi: Use scoped device node handling to fix missing of_node_put
Two return statements in sbi_cpuidle_dt_init_states() did not drop the OF node reference count. Solve the issue and simplify entire error handling with scoped/cleanup.h. Fixes: 6abf32f ("cpuidle: Add RISC-V SBI CPU idle driver") Cc: All applicable <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 5bb3321 commit a309320

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

drivers/cpuidle/cpuidle-riscv-sbi.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
1010

11+
#include <linux/cleanup.h>
1112
#include <linux/cpuhotplug.h>
1213
#include <linux/cpuidle.h>
1314
#include <linux/cpumask.h>
@@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
236237
{
237238
struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu);
238239
struct device_node *state_node;
239-
struct device_node *cpu_node;
240240
u32 *states;
241241
int i, ret;
242242

243-
cpu_node = of_cpu_device_node_get(cpu);
243+
struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu);
244244
if (!cpu_node)
245245
return -ENODEV;
246246

247247
states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL);
248-
if (!states) {
249-
ret = -ENOMEM;
250-
goto fail;
251-
}
248+
if (!states)
249+
return -ENOMEM;
252250

253251
/* Parse SBI specific details from state DT nodes */
254252
for (i = 1; i < state_count; i++) {
@@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev,
264262

265263
pr_debug("sbi-state %#x index %d\n", states[i], i);
266264
}
267-
if (i != state_count) {
268-
ret = -ENODEV;
269-
goto fail;
270-
}
265+
if (i != state_count)
266+
return -ENODEV;
271267

272268
/* Initialize optional data, used for the hierarchical topology. */
273269
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,
277273
/* Store states in the per-cpu struct. */
278274
data->states = states;
279275

280-
fail:
281-
of_node_put(cpu_node);
282-
283-
return ret;
276+
return 0;
284277
}
285278

286279
static void sbi_cpuidle_deinit_cpu(int cpu)

0 commit comments

Comments
 (0)