diff options
author | Ram Chandrasekar <rkumbako@codeaurora.org> | 2021-07-29 15:41:00 -0700 |
---|---|---|
committer | Ram Chandrasekar <rkumbako@codeaurora.org> | 2021-07-29 16:17:11 -0700 |
commit | 9e1b3262bb55a7cc2acc0b31621a95c03dcac6e2 (patch) | |
tree | 7fb501e08a37cfe56baca9e4e65777afe7883f21 /thermalConfig.cpp | |
parent | 372b93479a49d5b24443a28a1a8ad12dbe6a1749 (diff) |
thermal-hal: Add exception handling for stoi
stoi can throw exception when an invalid value is passed in buffer.
Enable exception handling and add retry mechanism when a exception is
thrown.
Change-Id: I2c1e0ddbbb408cb6b9739b516296125ec1efd64a
Diffstat (limited to 'thermalConfig.cpp')
-rw-r--r-- | thermalConfig.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/thermalConfig.cpp b/thermalConfig.cpp index c7086a5..ed65346 100644 --- a/thermalConfig.cpp +++ b/thermalConfig.cpp @@ -867,12 +867,24 @@ namespace implementation { std::vector<struct target_therm_cfg>::iterator it_vec; bool bcl_defined = false; std::string soc_val; - - if (cmnInst.readFromFile(socIDPath, soc_val) <= 0) { - LOG(ERROR) <<"soc ID fetch error"; - return; - } - soc_id = std::stoi(soc_val, nullptr, 0); + int ct = 0; + bool read_ok = false; + + do { + if (cmnInst.readFromFile(socIDPath, soc_val) <= 0) { + LOG(ERROR) <<"soc ID fetch error"; + return; + } + try { + soc_id = std::stoi(soc_val, nullptr, 0); + read_ok = true; + } + catch (std::exception &err) { + LOG(ERROR) <<"soc id stoi err:" << err.what() + << " buf:" << soc_val; + } + ct++; + } while (!read_ok && ct < RETRY_CT); if (soc_id <= 0) { LOG(ERROR) << "Invalid soc ID: " << soc_id; return; |