Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exit: reparent: cleanup the usage of reparent_leader()

1. Now that reparent_leader() doesn't abuse ->sibling we can shift
list_move_tail() from reparent_leader() to forget_original_parent()
and turn it into a single list_splice_tail_init(). This also makes
BUG_ON(!list_empty()) and list_for_each_entry_safe() unnecessary.

2. This also allows to shift the same_thread_group() check, it looks
a bit more clear in the caller.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Aaron Tomlin <atomlin@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Cc: Sterling Alexander <stalexan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@hack.frob.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Linus Torvalds
2831096e 57a05918

+9 -13
+9 -13
kernel/exit.c
··· 529 529 static void reparent_leader(struct task_struct *father, struct task_struct *p, 530 530 struct list_head *dead) 531 531 { 532 - list_move_tail(&p->sibling, &p->real_parent->children); 533 - 534 - if (p->exit_state == EXIT_DEAD) 535 - return; 536 - /* 537 - * If this is a threaded reparent there is no need to 538 - * notify anyone anything has happened. 539 - */ 540 - if (same_thread_group(p->real_parent, father)) 532 + if (unlikely(p->exit_state == EXIT_DEAD)) 541 533 return; 542 534 543 535 /* We don't want people slaying init. */ ··· 560 568 exit_ptrace(father); 561 569 reaper = find_new_reaper(father); 562 570 563 - list_for_each_entry_safe(p, n, &father->children, sibling) { 571 + list_for_each_entry(p, &father->children, sibling) { 564 572 for_each_thread(p, t) { 565 573 t->real_parent = reaper; 566 574 BUG_ON((!t->ptrace) != (t->parent == father)); ··· 570 578 group_send_sig_info(t->pdeath_signal, 571 579 SEND_SIG_NOINFO, t); 572 580 } 573 - reparent_leader(father, p, &dead_children); 581 + /* 582 + * If this is a threaded reparent there is no need to 583 + * notify anyone anything has happened. 584 + */ 585 + if (!same_thread_group(reaper, father)) 586 + reparent_leader(father, p, &dead_children); 574 587 } 588 + list_splice_tail_init(&father->children, &reaper->children); 575 589 write_unlock_irq(&tasklist_lock); 576 - 577 - BUG_ON(!list_empty(&father->children)); 578 590 579 591 list_for_each_entry_safe(p, n, &dead_children, ptrace_entry) { 580 592 list_del_init(&p->ptrace_entry);