@@ -286,6 +286,7 @@ ucs_status_t ucs_topo_find_device_by_bus_id(const ucs_sys_bus_id_t *bus_id,
286286 ucs_bus_id_bit_rep_t bus_id_bit_rep ;
287287 int kh_put_status ;
288288 khiter_t hash_it ;
289+ ucs_status_t status ;
289290 char * name ;
290291
291292 bus_id_bit_rep = ucs_topo_get_bus_id_bit_repr (bus_id );
@@ -298,6 +299,7 @@ ucs_status_t ucs_topo_find_device_by_bus_id(const ucs_sys_bus_id_t *bus_id,
298299
299300 if (kh_put_status == UCS_KH_PUT_KEY_PRESENT ) {
300301 * sys_dev = kh_value (& ucs_topo_global_ctx .bus_to_sys_dev_hash , hash_it );
302+ status = UCS_OK ;
301303 } else if ((kh_put_status == UCS_KH_PUT_BUCKET_EMPTY ) ||
302304 (kh_put_status == UCS_KH_PUT_BUCKET_CLEAR )) {
303305 ucs_assert_always (ucs_topo_global_ctx .num_devices <
@@ -309,10 +311,16 @@ ucs_status_t ucs_topo_find_device_by_bus_id(const ucs_sys_bus_id_t *bus_id,
309311
310312 /* Set default name to abbreviated BDF */
311313 name = ucs_malloc (UCS_SYS_BDF_NAME_MAX , "sys_dev_bdf_name" );
312- if (name != NULL ) {
313- ucs_topo_bus_id_str (bus_id , 1 , name , UCS_SYS_BDF_NAME_MAX );
314+ if (name == NULL ) {
315+ ucs_error ("failed to allocate memory for sys_dev_bdf_name" );
316+ status = UCS_ERR_NO_MEMORY ;
317+ kh_del (bus_to_sys_dev , & ucs_topo_global_ctx .bus_to_sys_dev_hash ,
318+ hash_it );
319+ goto out ;
314320 }
315321
322+ ucs_topo_bus_id_str (bus_id , 1 , name , UCS_SYS_BDF_NAME_MAX );
323+
316324 ucs_topo_global_ctx .devices [* sys_dev ].bus_id = * bus_id ;
317325 ucs_topo_global_ctx .devices [* sys_dev ].name = name ;
318326 ucs_topo_global_ctx .devices [* sys_dev ].name_priority = 0 ;
@@ -327,10 +335,15 @@ ucs_status_t ucs_topo_find_device_by_bus_id(const ucs_sys_bus_id_t *bus_id,
327335 UCS_SYS_DEVICE_ID_UNKNOWN ;
328336
329337 ucs_debug ("added sys_dev %d for bus id %s" , * sys_dev , name );
338+ status = UCS_OK ;
339+ } else {
340+ ucs_error ("failed to put key into hash table" );
341+ status = UCS_ERR_IO_ERROR ;
330342 }
331343
344+ out :
332345 ucs_spin_unlock (& ucs_topo_global_ctx .lock );
333- return UCS_OK ;
346+ return status ;
334347}
335348
336349ucs_status_t ucs_topo_get_device_bus_id (ucs_sys_device_t sys_dev ,
0 commit comments