From d7829d21b04d3435d3051e0997e1c22d3486019c Mon Sep 17 00:00:00 2001 From: Leonardo Chiquitto Date: Thu, 13 Oct 2011 12:54:48 -0600 Subject: [PATCH] irqbalance: Fix detection of CPUs in sysfs The current approach still let wrong patterns like "cpu0_idle", "cpu000_idle", "cpu0idle" and "cpu10001a" pass through. Of course it's highly unlikely that directories with these names will ever show in /sys/devices/system/cpu/, but here's the patch against the latest git if you want to fix it. Signed-off-by: Leonardo Chiquitto Signed-off-by: Neil Horman --- cputree.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cputree.c b/cputree.c index cc6e077..2717977 100644 --- a/cputree.c +++ b/cputree.c @@ -27,6 +27,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -334,15 +335,17 @@ void parse_cpu_tree(void) if (!dir) return; do { + int num; + char pad; entry = readdir(dir); - if (entry && strlen(entry->d_name)>3 && strstr(entry->d_name,"cpu")) { + /* + * We only want to count real cpus, not cpufreq and + * cpuidle + */ + if (entry && + sscanf(entry->d_name, "cpu%d%c", &num, &pad) == 1 && + !strchr(entry->d_name, ' ')) { char new_path[PATH_MAX]; - /* - * We only want to count real cpus, not cpufreq and - * cpuidle - */ - if ((entry->d_name[3] < 0x30) | (entry->d_name[3] > 0x39)) - continue; sprintf(new_path, "/sys/devices/system/cpu/%s", entry->d_name); do_one_cpu(new_path); }