From 19c3e2aff93dfb23e91e10de9620254767862af3 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Sat, 24 Jun 2023 06:27:18 -0700 Subject: [PATCH 4/6] Improve handling of ContructBDFID errors Building on this package on Fedora reports this warning In file included from rpmbuild/BUILD/rocm_smi_lib-rocm-5.5.1/src/rocm_smi_main.cc:62: In member function 'amd::smi::Device::set_bdfid(unsigned long)', inlined from 'amd::smi::RocmSMI::Initialize(unsigned long)' at rpmbuild/BUILD/rocm_smi_lib-rocm-5.5.1/src/rocm_smi_main.cc:330:27: rpmbuild/BUILD/rocm_smi_lib-rocm-5.5.1/include/rocm_smi/rocm_smi_device.h:199:42: warning: 'bdfid' may be used uninitialized [-Wmaybe-uninitialized] 199 | void set_bdfid(uint64_t val) {bdfid_ = val;} | ~~~~~~~^~~~~ rpmbuild/BUILD/rocm_smi_lib-rocm-5.5.1/src/rocm_smi_main.cc: In member function 'amd::smi::RocmSMI::Initialize(unsigned long)': rpmbuild/BUILD/rocm_smi_lib-rocm-5.5.1/src/rocm_smi_main.cc:324:12: note: 'bdfid' was declared here 324 | uint64_t bdfid; | ^~~~~ Only set the bdfid when it is know to be valid. Signed-off-by: Tom Rix Change-Id: I839b4d2d2d4e3b25469cf5972245b9630da00c87 --- src/rocm_smi_main.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rocm_smi_main.cc b/src/rocm_smi_main.cc index 72b0d5d..3a5565d 100755 --- a/src/rocm_smi_main.cc +++ b/src/rocm_smi_main.cc @@ -345,8 +345,9 @@ RocmSMI::Initialize(uint64_t flags) { if (ConstructBDFID(devices_[i]->path(), &bdfid) != 0) { std::cerr << "Failed to construct BDFID." << std::endl; ret = 1; + } else { + devices_[i]->set_bdfid(bdfid); } - devices_[i]->set_bdfid(bdfid); } if (ret != 0) { throw amd::smi::rsmi_exception(RSMI_INITIALIZATION_ERROR, -- 2.40.1