diff options
author | TeYuan Wang <kamewang@google.com> | 2022-03-14 17:33:15 +0800 |
---|---|---|
committer | TeYuan Wang <kamewang@google.com> | 2022-04-01 17:13:19 +0800 |
commit | 2ec4c035928b20042a19aecfde252261526676aa (patch) | |
tree | fc63a81780ffa290306317d463ca8b7b01c147ef /thermal/utils/power_files.cpp | |
parent | 90d879de7c822455afaf48a76c6e309aca2dc022 (diff) |
thermal: enhance thermal config parsing
1. Trigger FATAL crash for invalid thermal config
2. Add boundary check for thermal threshold
Bug: 223856015
Bug: 124822954
Bug: 221077673
Test: Side load thermal config with overlapped thresholds and confirm thermHAL can trigger crash
Change-Id: I58221455f7e893bcd2c753e98d1b625ba36cdc75
Diffstat (limited to 'thermal/utils/power_files.cpp')
-rw-r--r-- | thermal/utils/power_files.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/thermal/utils/power_files.cpp b/thermal/utils/power_files.cpp index e0eb3ff..a559454 100644 --- a/thermal/utils/power_files.cpp +++ b/thermal/utils/power_files.cpp @@ -106,6 +106,10 @@ bool PowerFiles::registerPowerRailsToWatch(std::string_view sensor_name, std::st for (int j = 0; j < power_rail_info.power_sample_count; j++) { power_history[i].emplace(power_sample); } + } else { + LOG(ERROR) << "Could not find power rail " + << power_rail_info.virtual_power_rail_info->linked_power_rails[i]; + return false; } } } else { @@ -114,6 +118,9 @@ bool PowerFiles::registerPowerRailsToWatch(std::string_view sensor_name, std::st for (int j = 0; j < power_rail_info.power_sample_count; j++) { power_history[0].emplace(power_sample); } + } else { + LOG(ERROR) << "Could not find power rail " << power_rail_info.rail; + return false; } } @@ -237,10 +244,14 @@ bool PowerFiles::updateEnergyValues(void) { bool PowerFiles::getAveragePower(std::string_view power_rail, std::queue<PowerSample> *power_history, bool power_sample_update, float *avg_power) { - const auto curr_sample = energy_info_map_.at(power_rail.data()); bool ret = true; - const auto last_sample = power_history->front(); + + if (!energy_info_map_.count(power_rail.data())) { + LOG(ERROR) << " Could not find power rail " << power_rail.data(); + return false; + } + const auto curr_sample = energy_info_map_.at(power_rail.data()); const auto duration = curr_sample.duration - last_sample.duration; const auto deltaEnergy = curr_sample.energy_counter - last_sample.energy_counter; |