summaryrefslogtreecommitdiffstats
path: root/lib/cpuset.c
diff options
context:
space:
mode:
authorHeiko Carstens2011-09-09 11:19:34 +0200
committerKarel Zak2011-09-10 00:00:35 +0200
commit59fb133a029fea29e38a98b5177fc760a0c8dc17 (patch)
tree9cf2c4f7e4e3270b3cb544724376f9e9cdac6555 /lib/cpuset.c
parentlib,cpuset: enforce stricter parsing of cpu lists (diff)
downloadkernel-qcow2-util-linux-59fb133a029fea29e38a98b5177fc760a0c8dc17.tar.gz
kernel-qcow2-util-linux-59fb133a029fea29e38a98b5177fc760a0c8dc17.tar.xz
kernel-qcow2-util-linux-59fb133a029fea29e38a98b5177fc760a0c8dc17.zip
chcpu,cpuset: reduce code duplication for cpu list parsing
Reduce code duplication and print better error message if an unsupported cpu number was passed. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'lib/cpuset.c')
-rw-r--r--lib/cpuset.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/cpuset.c b/lib/cpuset.c
index ebaffccfb..c3b67a705 100644
--- a/lib/cpuset.c
+++ b/lib/cpuset.c
@@ -263,6 +263,11 @@ int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize)
/*
* Parses string with list of CPU ranges.
+ * Returns 0 on success.
+ * Returns 1 on error.
+ * Returns 2 if fail is set and a cpu number passed in the list doesn't fit
+ * into the cpu_set. If fail is not set cpu numbers that do not fit are
+ * ignored and 0 is returned instead.
*/
int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail)
{
@@ -303,7 +308,7 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail)
return 1;
while (a <= b) {
if (fail && (a >= max))
- return 1;
+ return 2;
CPU_SET_S(a, setsize, set);
a += s;
}