From 3d6e5c355d10dcd9d6336331c96935013ffcd3b1 Mon Sep 17 00:00:00 2001 From: Gerrit Renker Date: Tue, 28 Dec 2010 10:53:03 +0100 Subject: lscpu: avoid len = 0 as a consequence of maxcpus = 0 This problem was observed on an x86_64 Mobile AMD Sempron 3700+ where kernel_max returned "0" as the index of the highest CPU. As a consequence, several variables in lscpu, which relied on maxcpus >= 1 (in particular the 'len' value) were set to 0, resulting in the following errors: host>./lscpu lscpu: failed to read: /sys/devices/system/cpu/online: No such file or directory host> cat /sys/devices/system/cpu/kernel_max 0 The fix used by this patch is to interpret kernel_max as an index and maxcpus as a count >= 1, tested to work. Signed-off-by: Gerrit Renker Signed-off-by: Karel Zak --- sys-utils/lscpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sys-utils/lscpu.c') diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index ca2adb864..224d5f99b 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -392,7 +392,8 @@ read_basicinfo(struct lscpu_desc *desc) fclose(fp); if (path_exist(_PATH_SYS_SYSTEM "/cpu/kernel_max")) - maxcpus = path_getnum(_PATH_SYS_SYSTEM "/cpu/kernel_max"); + /* note that kernel_max is maximum index [NR_CPUS-1] */ + maxcpus = path_getnum(_PATH_SYS_SYSTEM "/cpu/kernel_max") + 1; else if (!sysrootlen) /* the root is '/' so we are working with data from the current kernel */ -- cgit v1.2.3-55-g7522