Commit 37340746 authored by Lai Jiangshan's avatar Lai Jiangshan Committed by Linus Torvalds

cpusets: fix bug when adding nonexistent cpu or mem

Adding a nonexistent cpu to a cpuset will be omitted quietly.  It should
return -EINVAL.

Example: (real_nr_cpus <= 4 < NR_CPUS or cpu#4 was just offline)

# cat cpus
0-1
# /bin/echo 4 > cpus
# /bin/echo $?
0
# cat cpus

#

The same occurs when add a nonexistent mem.
This patch will fix this bug.
And when *buf == "", the check is unneeded.
Signed-off-by: default avatarLai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: default avatarPaul Jackson <pj@sgi.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent aae8679b
...@@ -797,8 +797,10 @@ static int update_cpumask(struct cpuset *cs, char *buf) ...@@ -797,8 +797,10 @@ static int update_cpumask(struct cpuset *cs, char *buf)
retval = cpulist_parse(buf, trialcs.cpus_allowed); retval = cpulist_parse(buf, trialcs.cpus_allowed);
if (retval < 0) if (retval < 0)
return retval; return retval;
if (!cpus_subset(trialcs.cpus_allowed, cpu_online_map))
return -EINVAL;
} }
cpus_and(trialcs.cpus_allowed, trialcs.cpus_allowed, cpu_online_map);
retval = validate_change(cs, &trialcs); retval = validate_change(cs, &trialcs);
if (retval < 0) if (retval < 0)
return retval; return retval;
...@@ -932,9 +934,11 @@ static int update_nodemask(struct cpuset *cs, char *buf) ...@@ -932,9 +934,11 @@ static int update_nodemask(struct cpuset *cs, char *buf)
retval = nodelist_parse(buf, trialcs.mems_allowed); retval = nodelist_parse(buf, trialcs.mems_allowed);
if (retval < 0) if (retval < 0)
goto done; goto done;
if (!nodes_subset(trialcs.mems_allowed,
node_states[N_HIGH_MEMORY]))
return -EINVAL;
} }
nodes_and(trialcs.mems_allowed, trialcs.mems_allowed,
node_states[N_HIGH_MEMORY]);
oldmem = cs->mems_allowed; oldmem = cs->mems_allowed;
if (nodes_equal(oldmem, trialcs.mems_allowed)) { if (nodes_equal(oldmem, trialcs.mems_allowed)) {
retval = 0; /* Too easy - nothing to do */ retval = 0; /* Too easy - nothing to do */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment