irqbalance: fix invalid cpu mask parsing

Irq balancer scans the isolcpus and nohz_full kernel masks and adds the
corresponding CPUs to the banned_cpus mask. This works fine for valid masks,
but not for the default, emtpy masks. In this case when they read from the
sysfs they return empty strings, "\n" or "0x0, \n":

0000000: 000a
0000000: 0a

Irqbalancer reads them and blindly passes these values to the
__bitmap_parselist() function, which expects ASCII string format.
For this input the implementation always set the first bit indicating CPU 0.

Steps to Reproduce:
1. Make sure /sys/devices/system/cpu/nohz_full and
   /sys/devices/system/cpu/isolated are empty
2. run $ /usr/sbin/irqbalance -d --oneshot | grep Isolated

   Actual results:
   Isolated CPUs: 00000001

   Expected results:
   Isolated CPUs: 00000000

Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Signed-off-by: Neil Horman <nhorman@tuxdriver.com.
This commit is contained in:
Tadeusz Struk 2016-11-30 15:32:22 -08:00 committed by Neil Horman
parent aa04f78f78
commit 3c9a009658

View file

@ -84,7 +84,8 @@ static void setup_banned_cpus(void)
file = fopen("/sys/devices/system/cpu/isolated", "r");
if (file) {
if (getline(&line, &size, file) > 0) {
cpulist_parse(line, size, isolated_cpus);
if (strlen(line) && line[0] != '\n')
cpulist_parse(line, strlen(line), isolated_cpus);
free(line);
line = NULL;
size = 0;
@ -95,7 +96,8 @@ static void setup_banned_cpus(void)
file = fopen("/sys/devices/system/cpu/nohz_full", "r");
if (file) {
if (getline(&line, &size, file) > 0) {
cpulist_parse(line, size, nohz_full);
if (strlen(line) && line[0] != '\n')
cpulist_parse(line, strlen(line), nohz_full);
free(line);
line = NULL;
size = 0;