diff --git a/python_smi_tools/rocm_smi.py b/python_smi_tools/rocm_smi.py index 4771a29f8f..d0bb5ab365 100755 --- a/python_smi_tools/rocm_smi.py +++ b/python_smi_tools/rocm_smi.py @@ -785,12 +785,8 @@ def resetFans(deviceList): for device in deviceList: sensor_ind = c_uint32(0) ret = rocmsmi.rsmi_dev_fan_reset(device, sensor_ind) - if (ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED) or (ret == rsmi_status_t.RSMI_STATUS_PERMISSION): - if not rsmi_ret_ok(rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED, device, 'reset_fan'): - continue - else: - if rsmi_ret_ok(ret, device, 'reset_fan'): - printLog(device, 'Successfully reset fan speed to driver control', None) + if rsmi_ret_ok(ret, device, 'reset_fan'): + printLog(device, 'Successfully reset fan speed to driver control', None) printLogSpacer() diff --git a/src/rocm_smi_device.cc b/src/rocm_smi_device.cc index f859a9812e..3830d602aa 100755 --- a/src/rocm_smi_device.cc +++ b/src/rocm_smi_device.cc @@ -593,7 +593,6 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) { bool reg_file; int ret = isRegularFile(sysfs_path, ®_file); - if (ret != 0) { ss << "File did not exist - SYSFS file (" << sysfs_path << ") for DevInfoInfoType (" << RocmSMI::devInfoTypesStrings.at(type) @@ -804,7 +803,8 @@ int Device::readDevInfoBinary(DevInfoTypes type, std::size_t b_size, FILE *ptr; sysfs_path += "/device/"; sysfs_path += kDevAttribNameMap.at(type); - ptr = fopen(sysfs_path.c_str(), "rb"); + + ptr = fopen(sysfs_path.c_str(), "rb"); if (!ptr) { ss << "Could not read DevInfoBinary for DevInfoType (" << RocmSMI::devInfoTypesStrings.at(type) << ")" diff --git a/src/rocm_smi_utils.cc b/src/rocm_smi_utils.cc index 670d90faec..5009d3bd14 100755 --- a/src/rocm_smi_utils.cc +++ b/src/rocm_smi_utils.cc @@ -158,13 +158,15 @@ int isRegularFile(std::string fname, bool *is_reg) { struct stat file_stat; int ret; - assert(is_reg != nullptr); - ret = stat(fname.c_str(), &file_stat); if (ret) { return errno; } - *is_reg = S_ISREG(file_stat.st_mode); + + if (is_reg != nullptr) { + *is_reg = S_ISREG(file_stat.st_mode); + } + return 0; } @@ -192,6 +194,13 @@ int WriteSysfsStr(std::string path, std::string val) { } int ReadSysfsStr(std::string path, std::string *retStr) { + // On success, zero is returned. On error, -1 is returned, and + // errno is set to indicate the error. + auto is_regular_file_result = isRegularFile(path, nullptr); + if (is_regular_file_result != 0) { + return ENOENT; + } + std::stringstream ss; int ret = 0; std::ostringstream oss;