aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorCarlos Santos <casantos@redhat.com>2019-10-17 09:37:13 -0300
committerRichard Henderson <richard.henderson@linaro.org>2020-01-21 14:18:12 -1000
commit00b5032eaddb7193f03f0a28b10286244d2e2a7b (patch)
treedb60aa670ca04cdc384eef613d6a3d9d5ad1a416 /util
parent7b7d00e0a714e0bdcd4c8a76f0927e1c8f1b2121 (diff)
downloadqemu-00b5032eaddb7193f03f0a28b10286244d2e2a7b.zip
qemu-00b5032eaddb7193f03f0a28b10286244d2e2a7b.tar.gz
qemu-00b5032eaddb7193f03f0a28b10286244d2e2a7b.tar.bz2
util/cacheinfo: fix crash when compiling with uClibc
uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate. Handle this situation using the fallback values instead of crashing due to an assertion failure. Signed-off-by: Carlos Santos <casantos@redhat.com> Message-Id: <20191017123713.30192-1-casantos@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'util')
-rw-r--r--util/cacheinfo.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/util/cacheinfo.c b/util/cacheinfo.c
index ea6f3e9..d94dc6a 100644
--- a/util/cacheinfo.c
+++ b/util/cacheinfo.c
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
static void sys_cache_info(int *isize, int *dsize)
{
# ifdef _SC_LEVEL1_ICACHE_LINESIZE
- *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+ int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+ if (tmp_isize > 0) {
+ *isize = tmp_isize;
+ }
# endif
# ifdef _SC_LEVEL1_DCACHE_LINESIZE
- *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ if (tmp_dsize > 0) {
+ *dsize = tmp_dsize;
+ }
# endif
}
#endif /* sys_cache_info */