From b276ae6c2bcb538903f58c44fa8a631e9d3cdc10 Mon Sep 17 00:00:00 2001 From: Xiaodong Wang Date: Tue, 16 Jul 2024 21:28:36 -0700 Subject: [PATCH] Fix ASAN issue in DiscoverAmdgpuDevices I ran a test that exercised this code in dev mode and ASAN found a memory access issue due to the iterator returned by lower_bound being dereferenced unconditionally. I believe the right fix is to check if the iterator is within the map and if not go to the else branch Change-Id: I34fdce634791a09a89eee76c8b2b64a9607d57f9 Signed-off-by: Galantsev, Dmitrii [ROCm/amdsmi commit: 20668722977bf6fb250b0351087035b876d5559d] --- projects/amdsmi/rocm_smi/src/rocm_smi_main.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc b/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc index 4c6b019009..25c32b1f94 100755 --- a/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi_main.cc @@ -817,10 +817,10 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) { rsmi_status_t ret_unique_id = rsmi_dev_unique_id_get(cardAdded, &device_uuid); auto temp_numb_nodes = allSystemNodes.count(device_uuid); - auto primaryBdfId = - allSystemNodes.lower_bound(device_uuid)->second.s_location_id; - if (doesDeviceSupportPartitions && temp_numb_nodes > 1 + auto it = allSystemNodes.lower_bound(device_uuid); + if (it != allSystemNodes.end() && doesDeviceSupportPartitions && temp_numb_nodes > 1 && ret_unique_id == RSMI_STATUS_SUCCESS) { + auto primaryBdfId = it->second.s_location_id; // helps identify xgmi nodes (secondary nodes) easier AddToDeviceList(d_name, primaryBdfId); } else {