From: Gerrit Renker Date: Tue, 28 Dec 2010 09:53:03 +0000 (+0100) Subject: lscpu: avoid len = 0 as a consequence of maxcpus = 0 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d6e5c355d10dcd9d6336331c96935013ffcd3b1;p=util-linux 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 --- diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index ca2adb86..224d5f99 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 */