@@ -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,36 @@ 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 ;
941
+ // umf_result is already set to UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY
945
942
goto err_free_name ;
946
943
}
947
944
948
945
coarse_provider -> free_blocks =
949
946
ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
950
947
if (coarse_provider -> free_blocks == NULL ) {
951
948
LOG_ERR ("out of the host memory" );
952
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
949
+ // umf_result is already set to UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY
953
950
goto err_delete_ravl_upstream_blocks ;
954
951
}
955
952
956
953
coarse_provider -> all_blocks =
957
954
ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
958
955
if (coarse_provider -> all_blocks == NULL ) {
959
956
LOG_ERR ("out of the host memory" );
960
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
957
+ // umf_result is already set to UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY
961
958
goto err_delete_ravl_free_blocks ;
962
959
}
963
960
@@ -966,6 +963,7 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
966
963
967
964
if (utils_mutex_init (& coarse_provider -> lock ) == NULL ) {
968
965
LOG_ERR ("lock initialization failed" );
966
+ umf_result = UMF_RESULT_ERROR_UNKNOWN ;
969
967
goto err_delete_ravl_all_blocks ;
970
968
}
971
969
@@ -976,7 +974,7 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
976
974
coarse_memory_provider_alloc (
977
975
coarse_provider , coarse_params -> init_buffer_size , 0 , & init_buffer );
978
976
if (init_buffer == NULL ) {
979
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
977
+ // umf_result is already set to UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY
980
978
goto err_destroy_mutex ;
981
979
}
982
980
@@ -1069,11 +1067,6 @@ static void coarse_ravl_cb_rm_all_blocks_node(void *data, void *arg) {
1069
1067
}
1070
1068
1071
1069
static void coarse_memory_provider_finalize (void * provider ) {
1072
- if (provider == NULL ) {
1073
- assert (0 );
1074
- return ;
1075
- }
1076
-
1077
1070
coarse_memory_provider_t * coarse_provider =
1078
1071
(struct coarse_memory_provider_t * )provider ;
1079
1072
@@ -1199,21 +1192,16 @@ find_free_block(struct ravl *free_blocks, size_t size, size_t alignment,
1199
1192
return free_blocks_rm_ge (free_blocks , size + alignment , 0 ,
1200
1193
CHECK_ONLY_THE_FIRST_BLOCK );
1201
1194
1195
+ // unknown memory allocation strategy
1202
1196
default :
1203
- LOG_ERR ("unknown memory allocation strategy" );
1204
- assert (0 );
1205
- return NULL ;
1197
+ abort ();
1206
1198
}
1207
1199
}
1208
1200
1209
1201
static umf_result_t coarse_memory_provider_alloc (void * provider , size_t size ,
1210
1202
size_t alignment ,
1211
1203
void * * resultPtr ) {
1212
- umf_result_t umf_result = UMF_RESULT_SUCCESS ;
1213
-
1214
- if (provider == NULL ) {
1215
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1216
- }
1204
+ umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN ;
1217
1205
1218
1206
if (resultPtr == NULL ) {
1219
1207
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -1252,9 +1240,7 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1252
1240
umf_result =
1253
1241
create_aligned_block (coarse_provider , size , alignment , & curr );
1254
1242
if (umf_result != UMF_RESULT_SUCCESS ) {
1255
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1256
- LOG_ERR ("unlocking the lock failed" );
1257
- }
1243
+ utils_mutex_unlock (& coarse_provider -> lock );
1258
1244
return umf_result ;
1259
1245
}
1260
1246
}
@@ -1263,9 +1249,7 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1263
1249
// Split the current block and put the new block after the one that we use.
1264
1250
umf_result = split_current_block (coarse_provider , curr , size );
1265
1251
if (umf_result != UMF_RESULT_SUCCESS ) {
1266
- if (utils_mutex_unlock (& coarse_provider -> lock ) != 0 ) {
1267
- LOG_ERR ("unlocking the lock failed" );
1268
- }
1252
+ utils_mutex_unlock (& coarse_provider -> lock );
1269
1253
return umf_result ;
1270
1254
}
1271
1255
@@ -1284,28 +1268,23 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1284
1268
coarse_provider -> used_size += size ;
1285
1269
1286
1270
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
- }
1271
+ utils_mutex_unlock (& coarse_provider -> lock );
1292
1272
1293
1273
return UMF_RESULT_SUCCESS ;
1294
1274
}
1295
1275
1296
1276
// no suitable block found - try to get more memory from the upstream provider
1277
+ umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1297
1278
1298
1279
if (coarse_provider -> upstream_memory_provider == NULL ) {
1299
1280
LOG_ERR ("out of memory - no upstream memory provider given" );
1300
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1301
1281
goto err_unlock ;
1302
1282
}
1303
1283
1304
1284
umfMemoryProviderAlloc (coarse_provider -> upstream_memory_provider , size ,
1305
1285
alignment , resultPtr );
1306
1286
if (* resultPtr == NULL ) {
1307
1287
LOG_ERR ("out of memory - upstream memory provider allocation failed" );
1308
- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
1309
1288
goto err_unlock ;
1310
1289
}
1311
1290
@@ -1327,23 +1306,13 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
1327
1306
1328
1307
err_unlock :
1329
1308
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
- }
1309
+ utils_mutex_unlock (& coarse_provider -> lock );
1337
1310
1338
1311
return umf_result ;
1339
1312
}
1340
1313
1341
1314
static umf_result_t coarse_memory_provider_free (void * provider , void * ptr ,
1342
1315
size_t bytes ) {
1343
- if (provider == NULL ) {
1344
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1345
- }
1346
-
1347
1316
coarse_memory_provider_t * coarse_provider =
1348
1317
(struct coarse_memory_provider_t * )provider ;
1349
1318
@@ -1398,11 +1367,7 @@ static umf_result_t coarse_memory_provider_free(void *provider, void *ptr,
1398
1367
}
1399
1368
1400
1369
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
- }
1370
+ utils_mutex_unlock (& coarse_provider -> lock );
1406
1371
1407
1372
return UMF_RESULT_SUCCESS ;
1408
1373
}
@@ -1424,10 +1389,6 @@ static void coarse_memory_provider_get_last_native_error(void *provider,
1424
1389
static umf_result_t coarse_memory_provider_get_min_page_size (void * provider ,
1425
1390
void * ptr ,
1426
1391
size_t * pageSize ) {
1427
- if (provider == NULL ) {
1428
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1429
- }
1430
-
1431
1392
coarse_memory_provider_t * coarse_provider =
1432
1393
(struct coarse_memory_provider_t * )provider ;
1433
1394
@@ -1443,10 +1404,6 @@ static umf_result_t coarse_memory_provider_get_min_page_size(void *provider,
1443
1404
static umf_result_t
1444
1405
coarse_memory_provider_get_recommended_page_size (void * provider , size_t size ,
1445
1406
size_t * pageSize ) {
1446
- if (provider == NULL ) {
1447
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1448
- }
1449
-
1450
1407
coarse_memory_provider_t * coarse_provider =
1451
1408
(struct coarse_memory_provider_t * )provider ;
1452
1409
@@ -1460,10 +1417,6 @@ coarse_memory_provider_get_recommended_page_size(void *provider, size_t size,
1460
1417
}
1461
1418
1462
1419
static const char * coarse_memory_provider_get_name (void * provider ) {
1463
- if (provider == NULL ) {
1464
- return COARSE_BASE_NAME ;
1465
- }
1466
-
1467
1420
coarse_memory_provider_t * coarse_provider =
1468
1421
(struct coarse_memory_provider_t * )provider ;
1469
1422
@@ -1503,14 +1456,6 @@ static void ravl_cb_count_free(void *data, void *arg) {
1503
1456
static umf_result_t
1504
1457
coarse_memory_provider_get_stats (void * provider ,
1505
1458
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
1459
coarse_memory_provider_t * coarse_provider =
1515
1460
(struct coarse_memory_provider_t * )provider ;
1516
1461
@@ -1628,13 +1573,7 @@ static umf_result_t coarse_memory_provider_allocation_split(void *provider,
1628
1573
1629
1574
err_mutex_unlock :
1630
1575
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
- }
1576
+ utils_mutex_unlock (& coarse_provider -> lock );
1638
1577
1639
1578
return umf_result ;
1640
1579
}
@@ -1731,13 +1670,7 @@ static umf_result_t coarse_memory_provider_allocation_merge(void *provider,
1731
1670
1732
1671
err_mutex_unlock :
1733
1672
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
- }
1673
+ utils_mutex_unlock (& coarse_provider -> lock );
1741
1674
1742
1675
return umf_result ;
1743
1676
}
0 commit comments