util-linux/backport-lib-cpuset-exit-early-from-cpulist_parse.patch
2024-12-16 02:37:59 +00:00

44 lines
1.1 KiB
Diff

From 566b1d348897a34016653d6de040688a2c0a136c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
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=UTF-8
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 <thomas@t-8ch.de>
Reference:https://github.com/util-linux/util-linux/commit/566b1d348897a34016653d6de040688a2c0a136c
Conflict:NA
---
lib/cpuset.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/cpuset.c b/lib/cpuset.c
index 643537f6d..533b8ab30 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.33.0