Skip to content

Commit ed8e443

Browse files
anjutsudhakarmpe
authored andcommitted
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: Anju T Sudhakar <[email protected]> Reviewed-by: Madhavan Srinivasan <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent e767381 commit ed8e443

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

arch/powerpc/perf/imc-pmu.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,16 @@ static void cleanup_all_thread_imc_memory(void)
11571157
}
11581158
}
11591159

1160+
/* Function to free the attr_groups which are dynamically allocated */
1161+
static void imc_common_mem_free(struct imc_pmu *pmu_ptr)
1162+
{
1163+
if (pmu_ptr->attr_groups[IMC_EVENT_ATTR])
1164+
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
1165+
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
1166+
kfree(pmu_ptr);
1167+
kfree(per_nest_pmu_arr);
1168+
}
1169+
11601170
/*
11611171
* Common function to unregister cpu hotplug callback and
11621172
* free the memory.
@@ -1188,14 +1198,6 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
11881198
cpuhp_remove_state(CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE);
11891199
cleanup_all_thread_imc_memory();
11901200
}
1191-
1192-
/* Only free the attr_groups which are dynamically allocated */
1193-
if (pmu_ptr->attr_groups[IMC_EVENT_ATTR])
1194-
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
1195-
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
1196-
kfree(pmu_ptr);
1197-
kfree(per_nest_pmu_arr);
1198-
return;
11991201
}
12001202

12011203

@@ -1244,8 +1246,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
12441246
core_imc_refc = kcalloc(nr_cores, sizeof(struct imc_pmu_ref),
12451247
GFP_KERNEL);
12461248

1247-
if (!core_imc_refc)
1249+
if (!core_imc_refc) {
1250+
kfree(pmu_ptr->mem_info);
12481251
return -ENOMEM;
1252+
}
12491253

12501254
core_imc_pmu = pmu_ptr;
12511255
break;
@@ -1258,8 +1262,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
12581262
thread_imc_mem_size = pmu_ptr->counter_mem_size;
12591263
for_each_online_cpu(cpu) {
12601264
res = thread_imc_mem_alloc(cpu, pmu_ptr->counter_mem_size);
1261-
if (res)
1265+
if (res) {
1266+
cleanup_all_thread_imc_memory();
12621267
return res;
1268+
}
12631269
}
12641270

12651271
break;
@@ -1285,8 +1291,10 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
12851291
int ret;
12861292

12871293
ret = imc_mem_init(pmu_ptr, parent, pmu_idx);
1288-
if (ret)
1289-
goto err_free;
1294+
if (ret) {
1295+
imc_common_mem_free(pmu_ptr);
1296+
return ret;
1297+
}
12901298

12911299
switch (pmu_ptr->domain) {
12921300
case IMC_DOMAIN_NEST:
@@ -1351,6 +1359,7 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
13511359
return 0;
13521360

13531361
err_free:
1362+
imc_common_mem_free(pmu_ptr);
13541363
imc_common_cpuhp_mem_free(pmu_ptr);
13551364
return ret;
13561365
}

0 commit comments

Comments
 (0)