msm_perf: Avoiding race condition during pmu counter init

Moved hot plug notification to occur after pmu_counter
initialization. Added sanity check before freeing pmu
counters to avoid kernel crash.

Change-Id: I1b7214746f0e8cbcf465df28d8ff875d2abd4950
Signed-off-by: Rajat Asthana <quic_rasthana@quicinc.com>
This commit is contained in:
Rajat Asthana 2024-05-02 14:10:47 +05:30
parent 6a5fe5d06c
commit 1278ab29b0

View File

@ -627,6 +627,9 @@ static void free_pmu_counters(unsigned int cpu)
{
int i = 0;
if (!cpu_possible(cpu))
return;
for (i = 0; i < NO_OF_EVENT; i++) {
pmu_events[i][cpu].prev_count = 0;
pmu_events[i][cpu].cur_delta = 0;
@ -1528,6 +1531,18 @@ static int __init msm_performance_init(void)
return -ENOMEM;
}
msm_perf_kset = kset_create_and_add("msm_performance", NULL, kernel_kobj);
if (!msm_perf_kset) {
free_cpumask_var(limit_mask_min);
free_cpumask_var(limit_mask_max);
return -ENOMEM;
}
add_module_params();
init_events_group();
init_notify_group();
init_pmu_counter();
cpus_read_lock();
for_each_possible_cpu(cpu) {
if (!cpumask_test_cpu(cpu, cpu_online_mask))
@ -1541,18 +1556,6 @@ static int __init msm_performance_init(void)
cpus_read_unlock();
msm_perf_kset = kset_create_and_add("msm_performance", NULL, kernel_kobj);
if (!msm_perf_kset) {
free_cpumask_var(limit_mask_min);
free_cpumask_var(limit_mask_max);
return -ENOMEM;
}
add_module_params();
init_events_group();
init_notify_group();
init_pmu_counter();
platform_driver_register(&scmi_plh_driver);
return 0;