From 731429f207577236f8ce42e3a6d2e0448920fd20 Mon Sep 17 00:00:00 2001 From: Yunfeng Ye Date: Fri, 24 Jul 2020 09:48:57 +0800 Subject: [PATCH] Add strlen checking for IRQBALANCE_BANNED_CPUS When the environment variable IRQBALANCE_BANNED_CPUS is not specifily the cpu, we expect do not place IRQs on CPUs the kernel keeps isolated or nohz_full. But currently, it will go to call cpumask_parse_user and ignore the isolated or nohz_full. so add strlen checking before calling cpumask_parse_user. --- cputree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cputree.c b/cputree.c index bef1f40..0433657 100644 --- a/cputree.c +++ b/cputree.c @@ -110,6 +110,7 @@ static void setup_banned_cpus(void) char buffer[4096]; cpumask_t nohz_full; cpumask_t isolated_cpus; + char *env = NULL; cpus_clear(isolated_cpus); cpus_clear(nohz_full); @@ -120,8 +121,9 @@ static void setup_banned_cpus(void) strlen(banned_cpumask_from_ui), banned_cpus); goto out; } - if (getenv("IRQBALANCE_BANNED_CPUS")) { - cpumask_parse_user(getenv("IRQBALANCE_BANNED_CPUS"), strlen(getenv("IRQBALANCE_BANNED_CPUS")), banned_cpus); + env = getenv("IRQBALANCE_BANNED_CPUS"); + if (env && strlen(env)) { + cpumask_parse_user(env, strlen(env), banned_cpus); goto out; }