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 <dmitrii.galantsev@amd.com>
Dieser Commit ist enthalten in:
Xiaodong Wang
2024-07-16 21:28:36 -07:00
committet von Dmitrii Galantsev
Ursprung d40e4d18a0
Commit 2066872297
+3 -3
Datei anzeigen
@@ -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 {