taskstats: add_del_listener() shouldn't use the wrong node
1. Commit 26c4caea9d
"don't allow duplicate entries in listener mode"
changed add_del_listener(REGISTER) so that "next_cpu:" can reuse the
listener allocated for the previous cpu, this doesn't look exactly
right even if minor.
Change the code to kfree() in the already-registered case, this case
is unlikely anyway so the extra kmalloc_node() shouldn't hurt but
looke more correct and clean.
2. use the plain list_for_each_entry() instead of _safe() to scan
listeners->list.
3. Remove the unneeded INIT_LIST_HEAD(&s->list), we are going to
list_add(&s->list).
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Vasiliy Kulikov <segoon@openwall.com>
Cc: Balbir Singh <bsingharora@gmail.com>
Reviewed-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
12b3e038e5
commit
dfc428b656
1 changed files with 7 additions and 9 deletions
|
@ -291,30 +291,28 @@ static int add_del_listener(pid_t pid, const struct cpumask *mask, int isadd)
|
||||||
if (!cpumask_subset(mask, cpu_possible_mask))
|
if (!cpumask_subset(mask, cpu_possible_mask))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
s = NULL;
|
|
||||||
if (isadd == REGISTER) {
|
if (isadd == REGISTER) {
|
||||||
for_each_cpu(cpu, mask) {
|
for_each_cpu(cpu, mask) {
|
||||||
if (!s)
|
s = kmalloc_node(sizeof(struct listener),
|
||||||
s = kmalloc_node(sizeof(struct listener),
|
GFP_KERNEL, cpu_to_node(cpu));
|
||||||
GFP_KERNEL, cpu_to_node(cpu));
|
|
||||||
if (!s)
|
if (!s)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
s->pid = pid;
|
s->pid = pid;
|
||||||
INIT_LIST_HEAD(&s->list);
|
|
||||||
s->valid = 1;
|
s->valid = 1;
|
||||||
|
|
||||||
listeners = &per_cpu(listener_array, cpu);
|
listeners = &per_cpu(listener_array, cpu);
|
||||||
down_write(&listeners->sem);
|
down_write(&listeners->sem);
|
||||||
list_for_each_entry_safe(s2, tmp, &listeners->list, list) {
|
list_for_each_entry(s2, &listeners->list, list) {
|
||||||
if (s2->pid == pid)
|
if (s2->pid == pid)
|
||||||
goto next_cpu;
|
goto exists;
|
||||||
}
|
}
|
||||||
list_add(&s->list, &listeners->list);
|
list_add(&s->list, &listeners->list);
|
||||||
s = NULL;
|
s = NULL;
|
||||||
next_cpu:
|
exists:
|
||||||
up_write(&listeners->sem);
|
up_write(&listeners->sem);
|
||||||
|
kfree(s); /* nop if NULL */
|
||||||
}
|
}
|
||||||
kfree(s);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue