@@ -413,11 +413,9 @@ static block_t *free_blocks_rm_ge(struct ravl *free_blocks, size_t size,
413413 case CHECK_ALL_BLOCKS_OF_SIZE :
414414 block = node_list_rm_with_alignment (head_node , alignment );
415415 break ;
416+ // wrong value of check_blocks
416417 default :
417- LOG_DEBUG ("wrong value of check_blocks" );
418- block = NULL ;
419- assert (0 );
420- break ;
418+ abort ();
421419 }
422420
423421 if (head_node -> head == NULL ) {
@@ -863,11 +861,7 @@ static umf_result_t coarse_memory_provider_free(void *provider, void *ptr,
863861
864862static umf_result_t coarse_memory_provider_initialize (void * params ,
865863 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 );
871865
872866 if (params == NULL ) {
873867 LOG_ERR ("coarse provider parameters are missing" );
@@ -931,33 +925,33 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
931925 coarse_provider -> disable_upstream_provider_free = false;
932926 }
933927
934- umf_result = coarse_memory_provider_set_name (coarse_provider );
928+ umf_result_t umf_result = coarse_memory_provider_set_name (coarse_provider );
935929 if (umf_result != UMF_RESULT_SUCCESS ) {
936930 LOG_ERR ("name initialization failed" );
937931 goto err_free_coarse_provider ;
938932 }
939933
934+ // most of the error handling paths below set this error
935+ umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
936+
940937 coarse_provider -> upstream_blocks =
941938 ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
942939 if (coarse_provider -> upstream_blocks == NULL ) {
943940 LOG_ERR ("out of the host memory" );
944- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
945941 goto err_free_name ;
946942 }
947943
948944 coarse_provider -> free_blocks =
949945 ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
950946 if (coarse_provider -> free_blocks == NULL ) {
951947 LOG_ERR ("out of the host memory" );
952- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
953948 goto err_delete_ravl_upstream_blocks ;
954949 }
955950
956951 coarse_provider -> all_blocks =
957952 ravl_new_sized (coarse_ravl_comp , sizeof (ravl_data_t ));
958953 if (coarse_provider -> all_blocks == NULL ) {
959954 LOG_ERR ("out of the host memory" );
960- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
961955 goto err_delete_ravl_free_blocks ;
962956 }
963957
@@ -966,6 +960,7 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
966960
967961 if (utils_mutex_init (& coarse_provider -> lock ) == NULL ) {
968962 LOG_ERR ("lock initialization failed" );
963+ umf_result = UMF_RESULT_ERROR_UNKNOWN ;
969964 goto err_delete_ravl_all_blocks ;
970965 }
971966
@@ -976,7 +971,6 @@ static umf_result_t coarse_memory_provider_initialize(void *params,
976971 coarse_memory_provider_alloc (
977972 coarse_provider , coarse_params -> init_buffer_size , 0 , & init_buffer );
978973 if (init_buffer == NULL ) {
979- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
980974 goto err_destroy_mutex ;
981975 }
982976
@@ -1069,11 +1063,6 @@ static void coarse_ravl_cb_rm_all_blocks_node(void *data, void *arg) {
10691063}
10701064
10711065static void coarse_memory_provider_finalize (void * provider ) {
1072- if (provider == NULL ) {
1073- assert (0 );
1074- return ;
1075- }
1076-
10771066 coarse_memory_provider_t * coarse_provider =
10781067 (struct coarse_memory_provider_t * )provider ;
10791068
@@ -1199,21 +1188,16 @@ find_free_block(struct ravl *free_blocks, size_t size, size_t alignment,
11991188 return free_blocks_rm_ge (free_blocks , size + alignment , 0 ,
12001189 CHECK_ONLY_THE_FIRST_BLOCK );
12011190
1191+ // unknown memory allocation strategy
12021192 default :
1203- LOG_ERR ("unknown memory allocation strategy" );
1204- assert (0 );
1205- return NULL ;
1193+ abort ();
12061194 }
12071195}
12081196
12091197static umf_result_t coarse_memory_provider_alloc (void * provider , size_t size ,
12101198 size_t alignment ,
12111199 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 ;
12171201
12181202 if (resultPtr == NULL ) {
12191203 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -1252,9 +1236,7 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
12521236 umf_result =
12531237 create_aligned_block (coarse_provider , size , alignment , & curr );
12541238 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 );
12581240 return umf_result ;
12591241 }
12601242 }
@@ -1263,9 +1245,7 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
12631245 // Split the current block and put the new block after the one that we use.
12641246 umf_result = split_current_block (coarse_provider , curr , size );
12651247 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 );
12691249 return umf_result ;
12701250 }
12711251
@@ -1284,28 +1264,23 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
12841264 coarse_provider -> used_size += size ;
12851265
12861266 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 );
12921268
12931269 return UMF_RESULT_SUCCESS ;
12941270 }
12951271
12961272 // no suitable block found - try to get more memory from the upstream provider
1273+ umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
12971274
12981275 if (coarse_provider -> upstream_memory_provider == NULL ) {
12991276 LOG_ERR ("out of memory - no upstream memory provider given" );
1300- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
13011277 goto err_unlock ;
13021278 }
13031279
13041280 umfMemoryProviderAlloc (coarse_provider -> upstream_memory_provider , size ,
13051281 alignment , resultPtr );
13061282 if (* resultPtr == NULL ) {
13071283 LOG_ERR ("out of memory - upstream memory provider allocation failed" );
1308- umf_result = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
13091284 goto err_unlock ;
13101285 }
13111286
@@ -1327,23 +1302,13 @@ static umf_result_t coarse_memory_provider_alloc(void *provider, size_t size,
13271302
13281303err_unlock :
13291304 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 );
13371306
13381307 return umf_result ;
13391308}
13401309
13411310static umf_result_t coarse_memory_provider_free (void * provider , void * ptr ,
13421311 size_t bytes ) {
1343- if (provider == NULL ) {
1344- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1345- }
1346-
13471312 coarse_memory_provider_t * coarse_provider =
13481313 (struct coarse_memory_provider_t * )provider ;
13491314
@@ -1398,11 +1363,7 @@ static umf_result_t coarse_memory_provider_free(void *provider, void *ptr,
13981363 }
13991364
14001365 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 );
14061367
14071368 return UMF_RESULT_SUCCESS ;
14081369}
@@ -1424,10 +1385,6 @@ static void coarse_memory_provider_get_last_native_error(void *provider,
14241385static umf_result_t coarse_memory_provider_get_min_page_size (void * provider ,
14251386 void * ptr ,
14261387 size_t * pageSize ) {
1427- if (provider == NULL ) {
1428- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1429- }
1430-
14311388 coarse_memory_provider_t * coarse_provider =
14321389 (struct coarse_memory_provider_t * )provider ;
14331390
@@ -1443,10 +1400,6 @@ static umf_result_t coarse_memory_provider_get_min_page_size(void *provider,
14431400static umf_result_t
14441401coarse_memory_provider_get_recommended_page_size (void * provider , size_t size ,
14451402 size_t * pageSize ) {
1446- if (provider == NULL ) {
1447- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1448- }
1449-
14501403 coarse_memory_provider_t * coarse_provider =
14511404 (struct coarse_memory_provider_t * )provider ;
14521405
@@ -1460,10 +1413,6 @@ coarse_memory_provider_get_recommended_page_size(void *provider, size_t size,
14601413}
14611414
14621415static const char * coarse_memory_provider_get_name (void * provider ) {
1463- if (provider == NULL ) {
1464- return COARSE_BASE_NAME ;
1465- }
1466-
14671416 coarse_memory_provider_t * coarse_provider =
14681417 (struct coarse_memory_provider_t * )provider ;
14691418
@@ -1503,14 +1452,6 @@ static void ravl_cb_count_free(void *data, void *arg) {
15031452static umf_result_t
15041453coarse_memory_provider_get_stats (void * provider ,
15051454 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-
15141455 coarse_memory_provider_t * coarse_provider =
15151456 (struct coarse_memory_provider_t * )provider ;
15161457
@@ -1628,13 +1569,7 @@ static umf_result_t coarse_memory_provider_allocation_split(void *provider,
16281569
16291570err_mutex_unlock :
16301571 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 );
16381573
16391574 return umf_result ;
16401575}
@@ -1731,13 +1666,7 @@ static umf_result_t coarse_memory_provider_allocation_merge(void *provider,
17311666
17321667err_mutex_unlock :
17331668 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 );
17411670
17421671 return umf_result ;
17431672}
0 commit comments