[PATCH] acpi: cstates: fix clang build warning on zero CPUs.
Colin King
colin.king at canonical.com
Wed Dec 16 14:53:00 UTC 2015
From: Colin Ian King <colin.king at canonical.com>
A small corner case were zero CPUs are available in
/sys/devices/system/cpu can cause a division by zero when
computing the tests progress. Bail out early and don't test
any CPUs rather if the number of CPUs is zero. This can
potentially occur if the /sys entries are not mounted.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/acpi/cstates/cstates.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
index 4bced4d..5e15732 100644
--- a/src/acpi/cstates/cstates.c
+++ b/src/acpi/cstates/cstates.c
@@ -217,7 +217,7 @@ static int cstates_test1(fwts_framework *fw)
}
/* How many CPUs are there? */
- for (cpus=0;(entry = readdir(dir)) != NULL;)
+ for (cpus = 0; (entry = readdir(dir)) != NULL;)
if (entry &&
(strlen(entry->d_name)>3) &&
(strncmp(entry->d_name, "cpu", 3) == 0) &&
@@ -226,7 +226,7 @@ static int cstates_test1(fwts_framework *fw)
rewinddir(dir);
- for (i=0;(entry = readdir(dir)) != NULL;) {
+ for (i = 0; (cpus > 0) && (entry = readdir(dir)) != NULL;) {
if (entry &&
(strlen(entry->d_name)>3) &&
(strncmp(entry->d_name, "cpu", 3) == 0) &&
--
2.6.4
More information about the fwts-devel
mailing list