From 566b1d348897a34016653d6de040688a2c0a136c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Thu, 1 Feb 2024 20:09:41 +0100 Subject: [PATCH] lib/cpuset: exit early from cpulist_parse MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If `a` exceeds `max`, any increment of `a` will also `exceed` max. In this case the CPU_SET_S will never do anything all additional loops are wasted. Fixes #2748 Signed-off-by: Thomas Weißschuh --- lib/cpuset.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cpuset.c b/lib/cpuset.c index 643537f6d9..533b8ab309 100644 --- a/lib/cpuset.c +++ b/lib/cpuset.c @@ -326,8 +326,12 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail) if (!(a <= b)) return 1; while (a <= b) { - if (fail && (a >= max)) - return 2; + if (a >= max) { + if (fail) + return 2; + else + break; + } CPU_SET_S(a, setsize, set); a += s; } -- 2.47.2