Skip to content

Commit 94f9bf1

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Fix of_node_* refcount
Fix of_node* refcount at various places by using of_node_put. Signed-off-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
1 parent 8b69961 commit 94f9bf1

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

arch/riscv/kernel/cacheinfo.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static int __init_cache_level(unsigned int cpu)
2828
{
2929
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
3030
struct device_node *np = of_cpu_device_node_get(cpu);
31+
struct device_node *prev = NULL;
3132
int levels = 0, leaves = 0, level;
3233

3334
if (of_property_read_bool(np, "cache-size"))
@@ -39,7 +40,10 @@ static int __init_cache_level(unsigned int cpu)
3940
if (leaves > 0)
4041
levels = 1;
4142

43+
prev = np;
4244
while ((np = of_find_next_cache_node(np))) {
45+
of_node_put(prev);
46+
prev = np;
4347
if (!of_device_is_compatible(np, "cache"))
4448
break;
4549
if (of_property_read_u32(np, "cache-level", &level))
@@ -55,8 +59,10 @@ static int __init_cache_level(unsigned int cpu)
5559
levels = level;
5660
}
5761

62+
of_node_put(np);
5863
this_cpu_ci->num_levels = levels;
5964
this_cpu_ci->num_leaves = leaves;
65+
6066
return 0;
6167
}
6268

@@ -65,6 +71,7 @@ static int __populate_cache_leaves(unsigned int cpu)
6571
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
6672
struct cacheinfo *this_leaf = this_cpu_ci->info_list;
6773
struct device_node *np = of_cpu_device_node_get(cpu);
74+
struct device_node *prev = NULL;
6875
int levels = 1, level = 1;
6976

7077
if (of_property_read_bool(np, "cache-size"))
@@ -74,7 +81,10 @@ static int __populate_cache_leaves(unsigned int cpu)
7481
if (of_property_read_bool(np, "d-cache-size"))
7582
ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
7683

84+
prev = np;
7785
while ((np = of_find_next_cache_node(np))) {
86+
of_node_put(prev);
87+
prev = np;
7888
if (!of_device_is_compatible(np, "cache"))
7989
break;
8090
if (of_property_read_u32(np, "cache-level", &level))
@@ -89,6 +99,7 @@ static int __populate_cache_leaves(unsigned int cpu)
8999
ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
90100
levels = level;
91101
}
102+
of_node_put(np);
92103

93104
return 0;
94105
}

arch/riscv/kernel/cpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static int c_show(struct seq_file *m, void *v)
158158
&& strcmp(compat, "riscv"))
159159
seq_printf(m, "uarch\t\t: %s\n", compat);
160160
seq_puts(m, "\n");
161+
of_node_put(node);
161162

162163
return 0;
163164
}

arch/riscv/kernel/cpufeature.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ void riscv_fill_hwcap(void)
5656

5757
if (of_property_read_string(node, "riscv,isa", &isa)) {
5858
pr_warning("Unable to find \"riscv,isa\" devicetree entry");
59+
of_node_put(node);
5960
return;
6061
}
62+
of_node_put(node);
6163

6264
for (i = 0; i < strlen(isa); ++i)
6365
elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];

arch/riscv/kernel/perf_event.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ int __init init_hw_perf_events(void)
476476

477477
if (of_id)
478478
riscv_pmu = of_id->data;
479+
of_node_put(node);
479480
}
480481

481482
perf_pmu_register(riscv_pmu->pmu, "cpu", PERF_TYPE_RAW);

arch/riscv/kernel/smpboot.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,23 @@ void __init setup_smp(void)
5757

5858
while ((dn = of_find_node_by_type(dn, "cpu"))) {
5959
hart = riscv_of_processor_hartid(dn);
60-
if (hart < 0)
60+
if (hart < 0) {
61+
of_node_put(dn);
6162
continue;
63+
}
6264

6365
if (hart == cpuid_to_hartid_map(0)) {
6466
BUG_ON(found_boot_cpu);
6567
found_boot_cpu = 1;
68+
of_node_put(dn);
6669
continue;
6770
}
6871

6972
cpuid_to_hartid_map(cpuid) = hart;
7073
set_cpu_possible(cpuid, true);
7174
set_cpu_present(cpuid, true);
7275
cpuid++;
76+
of_node_put(dn);
7377
}
7478

7579
BUG_ON(!found_boot_cpu);

0 commit comments

Comments
 (0)