Skip to content

Commit 83dd6c2

Browse files
Ruy Contributorscopybara-github
authored andcommitted
Null check each cpuinfo_get_processor call.
Add null checks in cases the cpuinfo could be faked and therefore not consistent. For example, the number of processors would be faked to be 8 but the rest of the processor info could be missing. PiperOrigin-RevId: 466965492
1 parent 97ebb72 commit 83dd6c2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ruy/cpuinfo.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void QueryCacheParams(CpuCacheParams* cache_params) {
4848
int local_cache_size = 0;
4949
int last_level_cache_size = 0;
5050
const cpuinfo_processor* processor = cpuinfo_get_processor(i);
51+
if (!processor) continue;
5152
// Loop over cache levels. Ignoring L4 for now: it seems that in CPUs that
5253
// have L4, we would still prefer to stay in lower-latency L3.
5354
for (const cpuinfo_cache* cache :
@@ -56,14 +57,16 @@ void QueryCacheParams(CpuCacheParams* cache_params) {
5657
continue; // continue, not break, it is possible to have L1+L3 but no
5758
// L2.
5859
}
59-
if (!cache->processor_count) {
60+
if (!cache->processor_count || !cache->processor_start) {
6061
continue; // crashes from Chrome on Android suggests that might happen?
6162
}
62-
const bool is_local =
63-
cpuinfo_get_processor(cache->processor_start)->core ==
64-
cpuinfo_get_processor(cache->processor_start +
65-
cache->processor_count - 1)
66-
->core;
63+
const cpuinfo_processor* start_processor =
64+
cpuinfo_get_processor(cache->processor_start);
65+
const cpuinfo_processor* end_processor = cpuinfo_get_processor(
66+
cache->processor_start + cache->processor_count - 1);
67+
if (!start_processor || !end_processor) continue;
68+
const bool is_local = start_processor->core == end_processor->core;
69+
6770
if (is_local) {
6871
local_cache_size = cache->size;
6972
}

0 commit comments

Comments
 (0)