aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2021-02-25 08:45:55 +0000
committerGeorgios Pinitas <georgios.pinitas@arm.com>2021-02-25 17:00:47 +0000
commit05784ada94f31ecfc1f64ef851af197ca3a172e5 (patch)
treec301f44ef98e9f7985860cc3ae01538ca7f535d6
parent9a67178b98783b1a886e633b0c1926a9072904ff (diff)
downloadComputeLibrary-05784ada94f31ecfc1f64ef851af197ca3a172e5.tar.gz
Add proper range checking when identifying CPU capabilities
Partially Resolves: COMPMID-4174 Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com> Change-Id: I4546440dfb60d6b3d80e31a0388be96d46539989 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5178 Reviewed-by: SiCong Li <sicong.li@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--src/runtime/CPUUtils.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/runtime/CPUUtils.cpp b/src/runtime/CPUUtils.cpp
index 6f51ee62e..63c9a8639 100644
--- a/src/runtime/CPUUtils.cpp
+++ b/src/runtime/CPUUtils.cpp
@@ -220,8 +220,9 @@ void populate_models_cpuinfo(std::vector<CPUModel> &cpusv)
if(file.is_open())
{
std::string line;
- int midr = 0;
- int curcpu = -1;
+ int midr = 0;
+ int curcpu = -1;
+ const int num_cpus = static_cast<int>(cpusv.size());
while(bool(getline(file, line)))
{
@@ -238,10 +239,14 @@ void populate_models_cpuinfo(std::vector<CPUModel> &cpusv)
return;
}
- if(curcpu >= 0)
+ if(curcpu >= 0 && curcpu < num_cpus)
{
cpusv[curcpu] = midr_to_model(midr);
}
+ else
+ {
+ ARM_COMPUTE_LOG_INFO_MSG_CORE("Trying to populate a core id with id greater than the expected number of cores!");
+ }
midr = 0;
curcpu = newcpu;
@@ -291,7 +296,7 @@ void populate_models_cpuinfo(std::vector<CPUModel> &cpusv)
}
}
- if(curcpu >= 0 && curcpu < static_cast<int>(cpusv.size()))
+ if(curcpu >= 0 && curcpu < num_cpus)
{
cpusv[curcpu] = midr_to_model(midr);
}