@@ -1157,6 +1157,16 @@ static void cleanup_all_thread_imc_memory(void)
1157
1157
}
1158
1158
}
1159
1159
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
+
1160
1170
/*
1161
1171
* Common function to unregister cpu hotplug callback and
1162
1172
* free the memory.
@@ -1188,14 +1198,6 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
1188
1198
cpuhp_remove_state (CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE );
1189
1199
cleanup_all_thread_imc_memory ();
1190
1200
}
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 ;
1199
1201
}
1200
1202
1201
1203
@@ -1244,8 +1246,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
1244
1246
core_imc_refc = kcalloc (nr_cores , sizeof (struct imc_pmu_ref ),
1245
1247
GFP_KERNEL );
1246
1248
1247
- if (!core_imc_refc )
1249
+ if (!core_imc_refc ) {
1250
+ kfree (pmu_ptr -> mem_info );
1248
1251
return - ENOMEM ;
1252
+ }
1249
1253
1250
1254
core_imc_pmu = pmu_ptr ;
1251
1255
break ;
@@ -1258,8 +1262,10 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
1258
1262
thread_imc_mem_size = pmu_ptr -> counter_mem_size ;
1259
1263
for_each_online_cpu (cpu ) {
1260
1264
res = thread_imc_mem_alloc (cpu , pmu_ptr -> counter_mem_size );
1261
- if (res )
1265
+ if (res ) {
1266
+ cleanup_all_thread_imc_memory ();
1262
1267
return res ;
1268
+ }
1263
1269
}
1264
1270
1265
1271
break ;
@@ -1285,8 +1291,10 @@ int init_imc_pmu(struct device_node *parent, struct imc_pmu *pmu_ptr, int pmu_id
1285
1291
int ret ;
1286
1292
1287
1293
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
+ }
1290
1298
1291
1299
switch (pmu_ptr -> domain ) {
1292
1300
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
1359
return 0 ;
1352
1360
1353
1361
err_free :
1362
+ imc_common_mem_free (pmu_ptr );
1354
1363
imc_common_cpuhp_mem_free (pmu_ptr );
1355
1364
return ret ;
1356
1365
}
0 commit comments