Commit ed8e443f authored by Anju T Sudhakar's avatar Anju T Sudhakar Committed by Michael Ellerman

powerpc/perf: IMC code cleanup with some code refactoring

Factor out memory freeing part for attribute elements from
imc_common_cpuhp_mem_free().
Signed-off-by: default avatarAnju T Sudhakar <anju@linux.vnet.ibm.com>
Reviewed-by: default avatarMadhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent e7673818
...@@ -1157,6 +1157,16 @@ static void cleanup_all_thread_imc_memory(void) ...@@ -1157,6 +1157,16 @@ static void cleanup_all_thread_imc_memory(void)
} }
} }
/* Function to free the attr_groups which are dynamically allocated */
static void imc_common_mem_free(struct imc_pmu *pmu_ptr)
{
if (pmu_ptr->attr_groups[IMC_EVENT_ATTR])
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
kfree(pmu_ptr);
kfree(per_nest_pmu_arr);
}
/* /*
* Common function to unregister cpu hotplug callback and * Common function to unregister cpu hotplug callback and
* free the memory. * free the memory.
...@@ -1188,14 +1198,6 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr) ...@@ -1188,14 +1198,6 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE); cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE);
cleanup_all_thread_imc_memory(); cleanup_all_thread_imc_memory();
} }
/* Only free the attr_groups which are dynamically allocated */
if (pmu_ptr->attr_groups[IMC_EVENT_ATTR])
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
kfree(pmu_ptr);
kfree(per_nest_pmu_arr);
return;
} }
...@@ -1244,8 +1246,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent, ...@@ -1244,8 +1246,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
core_imc_refc = kcalloc(nr_cores, sizeof(struct imc_pmu_ref), core_imc_refc = kcalloc(nr_cores, sizeof(struct imc_pmu_ref),
GFP_KERNEL); GFP_KERNEL);
if (!core_imc_refc) if (!core_imc_refc) {
kfree(pmu_ptr->mem_info);
return -ENOMEM; return -ENOMEM;
}
core_imc_pmu = pmu_ptr; core_imc_pmu = pmu_ptr;
break; break;
...@@ -1258,8 +1262,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent, ...@@ -1258,8 +1262,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
thread_imc_mem_size = pmu_ptr->counter_mem_size; thread_imc_mem_size = pmu_ptr->counter_mem_size;
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
res = thread_imc_mem_alloc(cpu, pmu_ptr->counter_mem_size); res = thread_imc_mem_alloc(cpu, pmu_ptr->counter_mem_size);
if (res) if (res) {
cleanup_all_thread_imc_memory();
return res; return res;
}
} }
break; break;
...@@ -1285,8 +1291,10 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id ...@@ -1285,8 +1291,10 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
int ret; int ret;
ret = imc_mem_init(pmu_ptr, parent, pmu_idx); ret = imc_mem_init(pmu_ptr, parent, pmu_idx);
if (ret) if (ret) {
goto err_free; imc_common_mem_free(pmu_ptr);
return ret;
}
switch (pmu_ptr->domain) { switch (pmu_ptr->domain) {
case IMC_DOMAIN_NEST: case IMC_DOMAIN_NEST:
...@@ -1351,6 +1359,7 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id ...@@ -1351,6 +1359,7 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
return 0; return 0;
err_free: err_free:
imc_common_mem_free(pmu_ptr);
imc_common_cpuhp_mem_free(pmu_ptr); imc_common_cpuhp_mem_free(pmu_ptr);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment