From 7c54dcba697d1f9874296a88ffd3e5c6f52473db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 14 Mar 2024 10:32:34 +0800 Subject: [PATCH] CPU (Linux): fix detection when `.../base_frequency` doesn't exist --- src/detection/cpu/cpu_linux.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index b011e51d3..dfc4984b0 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -102,7 +102,7 @@ static double getFrequency(FFstrbuf* basePath, const char* cpuinfoFileName, cons if (ok) return ffStrbufToDouble(buffer) / 1e6; } - + return 0.0/0.0; } @@ -114,7 +114,6 @@ static bool detectFrequency(FFCPUResult* cpu) FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); uint32_t baseLen = path.length; - bool flag = false; struct dirent* entry; while((entry = readdir(dir)) != NULL) @@ -123,25 +122,15 @@ static bool detectFrequency(FFCPUResult* cpu) { ffStrbufAppendS(&path, entry->d_name); double fbase = getFrequency(&path, "/base_frequency", NULL, &buffer); - if (fbase != fbase) continue; - double fmax = getFrequency(&path, "/cpuinfo_max_freq", "/scaling_max_freq", &buffer); - if (fmax != fmax) continue; - - if (flag) - { + if (fbase == fbase) cpu->frequencyBase = cpu->frequencyBase > fbase ? cpu->frequencyBase : fbase; + double fmax = getFrequency(&path, "/cpuinfo_max_freq", "/scaling_max_freq", &buffer); + if (fmax == fmax) cpu->frequencyMax = cpu->frequencyMax > fmax ? cpu->frequencyMax : fmax; - } - else - { - cpu->frequencyBase = fbase; - cpu->frequencyMax = fmax; - flag = true; - } ffStrbufSubstrBefore(&path, baseLen); } } - return flag; + return true; } static double detectCPUTemp(void)