@@ -413,11 +413,9 @@ static block_t *free_blocks_rm_ge(struct ravl *free_blocks, size_t size,
413
413
case CHECK_ALL_BLOCKS_OF_SIZE :
414
414
block = node_list_rm_with_alignment (head_node , alignment );
415
415
break ;
416
+ // wrong value of check_blocks
416
417
default :
417
- LOG_DEBUG ("wrong value of check_blocks" );
418
- block = NULL ;
419
- assert (0 );
420
- break ;
418
+ abort ();
421
419
}
422
420
423
421
if (head_node -> head == NULL ) {
@@ -863,11 +861,7 @@ static umf_result_t coarse_memory_provider_free(void *provider, void *ptr,
863
861
864
862
static umf_result_t coarse_memory_provider_initialize (void * params ,
865
863
void * * provider ) {
866
- umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN ;
867
-
868
- if (provider == NULL ) {
869
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
870
- }
864
+ assert (provider );
871
865
872
866
if (params == NULL ) {
873
867
LOG_ERR ("coarse provider parameters are missing" );
@@ -931,33 +925,33 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
931
925
coarse_provider -> disable_upstream_provider_free = false;
932
926
}
933
927
934
- umf_result = coarse_memory_provider_set_name (coarse_provider );
928
+ umf_result_t umf_result = coarse_memory_provider_set_name (coarse_provider );
935
929
if (umf_result != UMF_RESULT_SUCCESS ) {
936
930
LOG_ERR ("name initialization failed" );
937
931
goto err_free_coarse_provider ;
938
932
}
939
933
934
+ // most of the error handling paths below set this error
935
+ umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
936
+
940
937
coarse_provider -> upstream_blocks =
941
938
ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
942
939
if (coarse_provider -> upstream_blocks == NULL ) {
943
940
LOG_ERR ("out of the host memory" );
944
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
945
941
goto err_free_name ;
946
942
}
947
943
948
944
coarse_provider -> free_blocks =
949
945
ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
950
946
if (coarse_provider -> free_blocks == NULL ) {
951
947
LOG_ERR ("out of the host memory" );
952
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
953
948
goto err_delete_ravl_upstream_blocks ;
954
949
}
955
950
956
951
coarse_provider -> all_blocks =
957
952
ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
958
953
if (coarse_provider -> all_blocks == NULL ) {
959
954
LOG_ERR ("out of the host memory" );
960
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
961
955
goto err_delete_ravl_free_blocks ;
962
956
}
963
957
@@ -966,6 +960,7 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
966
960
967
961
if (utils_mutex_init (& coarse_provider -> lock ) == NULL ) {
968
962
LOG_ERR ("lock initialization failed" );
963
+ umf_result = UMF_RESULT_ERROR_UNKNOWN ;
969
964
goto err_delete_ravl_all_blocks ;
970
965
}
971
966
@@ -976,7 +971,6 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
976
971
coarse_memory_provider_alloc (
977
972
coarse_provider , coarse_params -> init_buffer_size , 0 , & init_buffer );
978
973
if (init_buffer == NULL ) {
979
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
980
974
goto err_destroy_mutex ;
981
975
}
982
976
@@ -1069,11 +1063,6 @@ static void coarse_ravl_cb_rm_all_blocks_node(void *data, void *arg) {
1069
1063
}
1070
1064
1071
1065
static void coarse_memory_provider_finalize (void * provider ) {
1072
- if (provider == NULL ) {
1073
- assert (0 );
1074
- return ;
1075
- }
1076
-
1077
1066
coarse_memory_provider_t * coarse_provider =
1078
1067
(struct coarse_memory_provider_t * )provider ;
1079
1068
@@ -1199,21 +1188,16 @@ find_free_block(struct ravl *free_blocks, size_t size, size_t alignment,
1199
1188
return free_blocks_rm_ge (free_blocks , size + alignment , 0 ,
1200
1189
CHECK_ONLY_THE_FIRST_BLOCK );
1201
1190
1191
+ // unknown memory allocation strategy
1202
1192
default :
1203
- LOG_ERR ("unknown memory allocation strategy" );
1204
- assert (0 );
1205
- return NULL ;
1193
+ abort ();
1206
1194
}
1207
1195
}
1208
1196
1209
1197
static umf_result_t coarse_memory_provider_alloc (void * provider , size_t size ,
1210
1198
size_t alignment ,
1211
1199
void * * resultPtr ) {
1212
- umf_result_t umf_result = UMF_RESULT_SUCCESS ;
1213
-
1214
- if (provider == NULL ) {
1215
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1216
- }
1200
+ umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN ;
1217
1201
1218
1202
if (resultPtr == NULL ) {
1219
1203
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -1252,9 +1236,7 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1252
1236
umf_result =
1253
1237
create_aligned_block (coarse_provider , size , alignment , & curr );
1254
1238
if (umf_result != UMF_RESULT_SUCCESS ) {
1255
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1256
- LOG_ERR ("unlocking the lock failed" );
1257
- }
1239
+ utils_mutex_unlock (& coarse_provider -> lock );
1258
1240
return umf_result ;
1259
1241
}
1260
1242
}
@@ -1263,9 +1245,7 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1263
1245
// Split the current block and put the new block after the one that we use.
1264
1246
umf_result = split_current_block (coarse_provider , curr , size );
1265
1247
if (umf_result != UMF_RESULT_SUCCESS ) {
1266
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1267
- LOG_ERR ("unlocking the lock failed" );
1268
- }
1248
+ utils_mutex_unlock (& coarse_provider -> lock );
1269
1249
return umf_result ;
1270
1250
}
1271
1251
@@ -1284,28 +1264,23 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1284
1264
coarse_provider -> used_size += size ;
1285
1265
1286
1266
assert (debug_check (coarse_provider ));
1287
-
1288
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1289
- LOG_ERR ("unlocking the lock failed" );
1290
- return UMF_RESULT_ERROR_UNKNOWN ;
1291
- }
1267
+ utils_mutex_unlock (& coarse_provider -> lock );
1292
1268
1293
1269
return UMF_RESULT_SUCCESS ;
1294
1270
}
1295
1271
1296
1272
// no suitable block found - try to get more memory from the upstream provider
1273
+ umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1297
1274
1298
1275
if (coarse_provider -> upstream_memory_provider == NULL ) {
1299
1276
LOG_ERR ("out of memory - no upstream memory provider given" );
1300
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1301
1277
goto err_unlock ;
1302
1278
}
1303
1279
1304
1280
umfMemoryProviderAlloc (coarse_provider -> upstream_memory_provider , size ,
1305
1281
alignment , resultPtr );
1306
1282
if (* resultPtr == NULL ) {
1307
1283
LOG_ERR ("out of memory - upstream memory provider allocation failed" );
1308
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1309
1284
goto err_unlock ;
1310
1285
}
1311
1286
@@ -1327,23 +1302,13 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1327
1302
1328
1303
err_unlock :
1329
1304
assert (debug_check (coarse_provider ));
1330
-
1331
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1332
- LOG_ERR ("unlocking the lock failed" );
1333
- if (umf_result == UMF_RESULT_SUCCESS ) {
1334
- umf_result = UMF_RESULT_ERROR_UNKNOWN ;
1335
- }
1336
- }
1305
+ utils_mutex_unlock (& coarse_provider -> lock );
1337
1306
1338
1307
return umf_result ;
1339
1308
}
1340
1309
1341
1310
static umf_result_t coarse_memory_provider_free (void * provider , void * ptr ,
1342
1311
size_t bytes ) {
1343
- if (provider == NULL ) {
1344
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1345
- }
1346
-
1347
1312
coarse_memory_provider_t * coarse_provider =
1348
1313
(struct coarse_memory_provider_t * )provider ;
1349
1314
@@ -1398,11 +1363,7 @@ static umf_result_t coarse_memory_provider_free(void *provider, void *ptr,
1398
1363
}
1399
1364
1400
1365
assert (debug_check (coarse_provider ));
1401
-
1402
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1403
- LOG_ERR ("unlocking the lock failed" );
1404
- return UMF_RESULT_ERROR_UNKNOWN ;
1405
- }
1366
+ utils_mutex_unlock (& coarse_provider -> lock );
1406
1367
1407
1368
return UMF_RESULT_SUCCESS ;
1408
1369
}
@@ -1424,10 +1385,6 @@ static void coarse_memory_provider_get_last_native_error(void *provider,
1424
1385
static umf_result_t coarse_memory_provider_get_min_page_size (void * provider ,
1425
1386
void * ptr ,
1426
1387
size_t * pageSize ) {
1427
- if (provider == NULL ) {
1428
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1429
- }
1430
-
1431
1388
coarse_memory_provider_t * coarse_provider =
1432
1389
(struct coarse_memory_provider_t * )provider ;
1433
1390
@@ -1443,10 +1400,6 @@ static umf_result_t coarse_memory_provider_get_min_page_size(void *provider,
1443
1400
static umf_result_t
1444
1401
coarse_memory_provider_get_recommended_page_size (void * provider , size_t size ,
1445
1402
size_t * pageSize ) {
1446
- if (provider == NULL ) {
1447
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1448
- }
1449
-
1450
1403
coarse_memory_provider_t * coarse_provider =
1451
1404
(struct coarse_memory_provider_t * )provider ;
1452
1405
@@ -1460,10 +1413,6 @@ coarse_memory_provider_get_recommended_page_size(void *provider, size_t size,
1460
1413
}
1461
1414
1462
1415
static const char * coarse_memory_provider_get_name (void * provider ) {
1463
- if (provider == NULL ) {
1464
- return COARSE_BASE_NAME ;
1465
- }
1466
-
1467
1416
coarse_memory_provider_t * coarse_provider =
1468
1417
(struct coarse_memory_provider_t * )provider ;
1469
1418
@@ -1503,14 +1452,6 @@ static void ravl_cb_count_free(void *data, void *arg) {
1503
1452
static umf_result_t
1504
1453
coarse_memory_provider_get_stats (void * provider ,
1505
1454
coarse_memory_provider_stats_t * stats ) {
1506
- if (provider == NULL ) {
1507
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1508
- }
1509
-
1510
- if (stats == NULL ) {
1511
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1512
- }
1513
-
1514
1455
coarse_memory_provider_t * coarse_provider =
1515
1456
(struct coarse_memory_provider_t * )provider ;
1516
1457
@@ -1628,13 +1569,7 @@ static umf_result_t coarse_memory_provider_allocation_split(void *provider,
1628
1569
1629
1570
err_mutex_unlock :
1630
1571
assert (debug_check (coarse_provider ));
1631
-
1632
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1633
- LOG_ERR ("unlocking the lock failed" );
1634
- if (umf_result == UMF_RESULT_SUCCESS ) {
1635
- umf_result = UMF_RESULT_ERROR_UNKNOWN ;
1636
- }
1637
- }
1572
+ utils_mutex_unlock (& coarse_provider -> lock );
1638
1573
1639
1574
return umf_result ;
1640
1575
}
@@ -1731,13 +1666,7 @@ static umf_result_t coarse_memory_provider_allocation_merge(void *provider,
1731
1666
1732
1667
err_mutex_unlock :
1733
1668
assert (debug_check (coarse_provider ));
1734
-
1735
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1736
- LOG_ERR ("unlocking the lock failed" );
1737
- if (umf_result == UMF_RESULT_SUCCESS ) {
1738
- umf_result = UMF_RESULT_ERROR_UNKNOWN ;
1739
- }
1740
- }
1669
+ utils_mutex_unlock (& coarse_provider -> lock );
1741
1670
1742
1671
return umf_result ;
1743
1672
}
0 commit comments