mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									8b699616f3
								
							
						
					
					
						commit
						94f9bf118f
					
				
					 5 changed files with 20 additions and 1 deletions
				
			
		| 
						 | 
					@ -28,6 +28,7 @@ static int __init_cache_level(unsigned int cpu)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
 | 
						struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
 | 
				
			||||||
	struct device_node *np = of_cpu_device_node_get(cpu);
 | 
						struct device_node *np = of_cpu_device_node_get(cpu);
 | 
				
			||||||
 | 
						struct device_node *prev = NULL;
 | 
				
			||||||
	int levels = 0, leaves = 0, level;
 | 
						int levels = 0, leaves = 0, level;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (of_property_read_bool(np, "cache-size"))
 | 
						if (of_property_read_bool(np, "cache-size"))
 | 
				
			||||||
| 
						 | 
					@ -39,7 +40,10 @@ static int __init_cache_level(unsigned int cpu)
 | 
				
			||||||
	if (leaves > 0)
 | 
						if (leaves > 0)
 | 
				
			||||||
		levels = 1;
 | 
							levels = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						prev = np;
 | 
				
			||||||
	while ((np = of_find_next_cache_node(np))) {
 | 
						while ((np = of_find_next_cache_node(np))) {
 | 
				
			||||||
 | 
							of_node_put(prev);
 | 
				
			||||||
 | 
							prev = np;
 | 
				
			||||||
		if (!of_device_is_compatible(np, "cache"))
 | 
							if (!of_device_is_compatible(np, "cache"))
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		if (of_property_read_u32(np, "cache-level", &level))
 | 
							if (of_property_read_u32(np, "cache-level", &level))
 | 
				
			||||||
| 
						 | 
					@ -55,8 +59,10 @@ static int __init_cache_level(unsigned int cpu)
 | 
				
			||||||
		levels = level;
 | 
							levels = level;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						of_node_put(np);
 | 
				
			||||||
	this_cpu_ci->num_levels = levels;
 | 
						this_cpu_ci->num_levels = levels;
 | 
				
			||||||
	this_cpu_ci->num_leaves = leaves;
 | 
						this_cpu_ci->num_leaves = leaves;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,6 +71,7 @@ static int __populate_cache_leaves(unsigned int cpu)
 | 
				
			||||||
	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
 | 
						struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
 | 
				
			||||||
	struct cacheinfo *this_leaf = this_cpu_ci->info_list;
 | 
						struct cacheinfo *this_leaf = this_cpu_ci->info_list;
 | 
				
			||||||
	struct device_node *np = of_cpu_device_node_get(cpu);
 | 
						struct device_node *np = of_cpu_device_node_get(cpu);
 | 
				
			||||||
 | 
						struct device_node *prev = NULL;
 | 
				
			||||||
	int levels = 1, level = 1;
 | 
						int levels = 1, level = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (of_property_read_bool(np, "cache-size"))
 | 
						if (of_property_read_bool(np, "cache-size"))
 | 
				
			||||||
| 
						 | 
					@ -74,7 +81,10 @@ static int __populate_cache_leaves(unsigned int cpu)
 | 
				
			||||||
	if (of_property_read_bool(np, "d-cache-size"))
 | 
						if (of_property_read_bool(np, "d-cache-size"))
 | 
				
			||||||
		ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
 | 
							ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						prev = np;
 | 
				
			||||||
	while ((np = of_find_next_cache_node(np))) {
 | 
						while ((np = of_find_next_cache_node(np))) {
 | 
				
			||||||
 | 
							of_node_put(prev);
 | 
				
			||||||
 | 
							prev = np;
 | 
				
			||||||
		if (!of_device_is_compatible(np, "cache"))
 | 
							if (!of_device_is_compatible(np, "cache"))
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		if (of_property_read_u32(np, "cache-level", &level))
 | 
							if (of_property_read_u32(np, "cache-level", &level))
 | 
				
			||||||
| 
						 | 
					@ -89,6 +99,7 @@ static int __populate_cache_leaves(unsigned int cpu)
 | 
				
			||||||
			ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
 | 
								ci_leaf_init(this_leaf++, np, CACHE_TYPE_DATA, level);
 | 
				
			||||||
		levels = level;
 | 
							levels = level;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						of_node_put(np);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,6 +158,7 @@ static int c_show(struct seq_file *m, void *v)
 | 
				
			||||||
	    && strcmp(compat, "riscv"))
 | 
						    && strcmp(compat, "riscv"))
 | 
				
			||||||
		seq_printf(m, "uarch\t\t: %s\n", compat);
 | 
							seq_printf(m, "uarch\t\t: %s\n", compat);
 | 
				
			||||||
	seq_puts(m, "\n");
 | 
						seq_puts(m, "\n");
 | 
				
			||||||
 | 
						of_node_put(node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,8 +56,10 @@ void riscv_fill_hwcap(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (of_property_read_string(node, "riscv,isa", &isa)) {
 | 
						if (of_property_read_string(node, "riscv,isa", &isa)) {
 | 
				
			||||||
		pr_warning("Unable to find \"riscv,isa\" devicetree entry");
 | 
							pr_warning("Unable to find \"riscv,isa\" devicetree entry");
 | 
				
			||||||
 | 
							of_node_put(node);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						of_node_put(node);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < strlen(isa); ++i)
 | 
						for (i = 0; i < strlen(isa); ++i)
 | 
				
			||||||
		elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
 | 
							elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -476,6 +476,7 @@ int __init init_hw_perf_events(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (of_id)
 | 
							if (of_id)
 | 
				
			||||||
			riscv_pmu = of_id->data;
 | 
								riscv_pmu = of_id->data;
 | 
				
			||||||
 | 
							of_node_put(node);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	perf_pmu_register(riscv_pmu->pmu, "cpu", PERF_TYPE_RAW);
 | 
						perf_pmu_register(riscv_pmu->pmu, "cpu", PERF_TYPE_RAW);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,12 +57,15 @@ void __init setup_smp(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while ((dn = of_find_node_by_type(dn, "cpu"))) {
 | 
						while ((dn = of_find_node_by_type(dn, "cpu"))) {
 | 
				
			||||||
		hart = riscv_of_processor_hartid(dn);
 | 
							hart = riscv_of_processor_hartid(dn);
 | 
				
			||||||
		if (hart < 0)
 | 
							if (hart < 0) {
 | 
				
			||||||
 | 
								of_node_put(dn);
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (hart == cpuid_to_hartid_map(0)) {
 | 
							if (hart == cpuid_to_hartid_map(0)) {
 | 
				
			||||||
			BUG_ON(found_boot_cpu);
 | 
								BUG_ON(found_boot_cpu);
 | 
				
			||||||
			found_boot_cpu = 1;
 | 
								found_boot_cpu = 1;
 | 
				
			||||||
 | 
								of_node_put(dn);
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,6 +73,7 @@ void __init setup_smp(void)
 | 
				
			||||||
		set_cpu_possible(cpuid, true);
 | 
							set_cpu_possible(cpuid, true);
 | 
				
			||||||
		set_cpu_present(cpuid, true);
 | 
							set_cpu_present(cpuid, true);
 | 
				
			||||||
		cpuid++;
 | 
							cpuid++;
 | 
				
			||||||
 | 
							of_node_put(dn);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BUG_ON(!found_boot_cpu);
 | 
						BUG_ON(!found_boot_cpu);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue