diff options
author | Karel Zak | 2012-11-13 10:36:25 +0100 |
---|---|---|
committer | Karel Zak | 2012-11-13 10:36:25 +0100 |
commit | d4bfa64d44e0515c59e5274d2384dedd9f9d4cc8 (patch) | |
tree | e2c9ecf0db356664444c485bb635dbf8d1ccaffb /sys-utils | |
parent | tests: add armv7 lscpu dump (diff) | |
download | kernel-qcow2-util-linux-d4bfa64d44e0515c59e5274d2384dedd9f9d4cc8.tar.gz kernel-qcow2-util-linux-d4bfa64d44e0515c59e5274d2384dedd9f9d4cc8.tar.xz kernel-qcow2-util-linux-d4bfa64d44e0515c59e5274d2384dedd9f9d4cc8.zip |
lscpu: make read_topology() more robust to avoid SIGFPE
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r-- | sys-utils/lscpu.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 5b1a0afee..a111561dc 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -627,16 +627,26 @@ read_topology(struct lscpu_desc *desc, int num) /* threads within one core */ nthreads = CPU_COUNT_S(setsize, thread_siblings); + if (!nthreads) + nthreads = 1; + /* cores within one socket */ ncores = CPU_COUNT_S(setsize, core_siblings) / nthreads; - /* number of sockets within one book. - * Because of odd / non-present cpu maps and to keep - * calculation easy we make sure that nsockets and - * nbooks is at least 1. + if (!ncores) + ncores = 1; + + /* number of sockets within one book. Because of odd / + * non-present cpu maps and to keep calculation easy we make + * sure that nsockets and nbooks is at least 1. */ - nsockets = desc->ncpus / nthreads / ncores ?: 1; + nsockets = desc->ncpus / nthreads / ncores; + if (!nsockets) + nsockets = 1; + /* number of books */ - nbooks = desc->ncpus / nthreads / ncores / nsockets ?: 1; + nbooks = desc->ncpus / nthreads / ncores / nsockets; + if (!nbooks) + nbooks = 1; /* all threads, see also read_basicinfo() * -- fallback for kernels without @@ -644,6 +654,7 @@ read_topology(struct lscpu_desc *desc, int num) */ if (!desc->nthreads) desc->nthreads = nbooks * nsockets * ncores * nthreads; + /* For each map we make sure that it can have up to ncpuspos * entries. This is because we cannot reliably calculate the * number of cores, sockets and books on all architectures. |