forked from mirrors/linux
		
	oprofile, ARM: Use oprofile_arch_exit() to cleanup on failure
There is duplicate cleanup code in the init and exit functions. Now, oprofile_arch_exit() is also used if oprofile_arch_init() fails. Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Robert Richter <robert.richter@amd.com>
This commit is contained in:
		
							parent
							
								
									2bcb2b641a
								
							
						
					
					
						commit
						e9677b3ce2
					
				
					 1 changed files with 26 additions and 28 deletions
				
			
		| 
						 | 
					@ -245,10 +245,33 @@ static int __init init_driverfs(void) { return 0; }
 | 
				
			||||||
#define exit_driverfs() do { } while (0)
 | 
					#define exit_driverfs() do { } while (0)
 | 
				
			||||||
#endif /* CONFIG_PM */
 | 
					#endif /* CONFIG_PM */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void oprofile_perf_exit(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int cpu, id;
 | 
				
			||||||
 | 
						struct perf_event *event;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for_each_possible_cpu(cpu) {
 | 
				
			||||||
 | 
							for (id = 0; id < num_counters; ++id) {
 | 
				
			||||||
 | 
								event = perf_events[cpu][id];
 | 
				
			||||||
 | 
								if (event)
 | 
				
			||||||
 | 
									perf_event_release_kernel(event);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							kfree(perf_events[cpu]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kfree(counter_config);
 | 
				
			||||||
 | 
						exit_driverfs();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int __init oprofile_perf_init(struct oprofile_operations *ops)
 | 
					int __init oprofile_perf_init(struct oprofile_operations *ops)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int cpu, ret = 0;
 | 
						int cpu, ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = init_driverfs();
 | 
				
			||||||
 | 
						if (ret)
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(&perf_events, 0, sizeof(perf_events));
 | 
						memset(&perf_events, 0, sizeof(perf_events));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	num_counters = perf_num_counters();
 | 
						num_counters = perf_num_counters();
 | 
				
			||||||
| 
						 | 
					@ -265,13 +288,10 @@ int __init oprofile_perf_init(struct oprofile_operations *ops)
 | 
				
			||||||
		pr_info("oprofile: failed to allocate %d "
 | 
							pr_info("oprofile: failed to allocate %d "
 | 
				
			||||||
				"counters\n", num_counters);
 | 
									"counters\n", num_counters);
 | 
				
			||||||
		ret = -ENOMEM;
 | 
							ret = -ENOMEM;
 | 
				
			||||||
 | 
							num_counters = 0;
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = init_driverfs();
 | 
					 | 
				
			||||||
	if (ret)
 | 
					 | 
				
			||||||
		goto out;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for_each_possible_cpu(cpu) {
 | 
						for_each_possible_cpu(cpu) {
 | 
				
			||||||
		perf_events[cpu] = kcalloc(num_counters,
 | 
							perf_events[cpu] = kcalloc(num_counters,
 | 
				
			||||||
				sizeof(struct perf_event *), GFP_KERNEL);
 | 
									sizeof(struct perf_event *), GFP_KERNEL);
 | 
				
			||||||
| 
						 | 
					@ -296,30 +316,8 @@ int __init oprofile_perf_init(struct oprofile_operations *ops)
 | 
				
			||||||
		pr_info("oprofile: using %s\n", ops->cpu_type);
 | 
							pr_info("oprofile: using %s\n", ops->cpu_type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
out:
 | 
					out:
 | 
				
			||||||
	if (ret) {
 | 
						if (ret)
 | 
				
			||||||
		for_each_possible_cpu(cpu)
 | 
							oprofile_perf_exit();
 | 
				
			||||||
			kfree(perf_events[cpu]);
 | 
					 | 
				
			||||||
		kfree(counter_config);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
void __exit oprofile_perf_exit(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int cpu, id;
 | 
					 | 
				
			||||||
	struct perf_event *event;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for_each_possible_cpu(cpu) {
 | 
					 | 
				
			||||||
		for (id = 0; id < num_counters; ++id) {
 | 
					 | 
				
			||||||
			event = perf_events[cpu][id];
 | 
					 | 
				
			||||||
			if (event)
 | 
					 | 
				
			||||||
				perf_event_release_kernel(event);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		kfree(perf_events[cpu]);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	kfree(counter_config);
 | 
					 | 
				
			||||||
	exit_driverfs();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue