coredump: simplify zap_process()
authorOleg Nesterov <oleg@redhat.com>
Tue, 25 Jun 2024 14:03:11 +0000 (16:03 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 5 Jul 2024 06:43:09 +0000 (23:43 -0700)
After commit 0258b5fd7c71 ("coredump: Limit coredumps to a single thread
group") zap_process() doesn't need the "task_struct *start" arg,
zap_threads() can pass "signal_struct *signal" instead.

This simplifies the code and allows to use __for_each_thread() which
is slightly more efficient.

Link: https://lkml.kernel.org/r/20240625140311.GA20787@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/coredump.c

index a57a06b80f571b9676d19517e0b644dd1db344d7..4dc5140bac3f1e46768e6ecf45071e6cdab5f2ff 100644 (file)
@@ -361,17 +361,16 @@ out:
        return ispipe;
 }
 
-static int zap_process(struct task_struct *start, int exit_code)
+static int zap_process(struct signal_struct *signal, int exit_code)
 {
        struct task_struct *t;
        int nr = 0;
 
-       /* Allow SIGKILL, see prepare_signal() */
-       start->signal->flags = SIGNAL_GROUP_EXIT;
-       start->signal->group_exit_code = exit_code;
-       start->signal->group_stop_count = 0;
+       signal->flags = SIGNAL_GROUP_EXIT;
+       signal->group_exit_code = exit_code;
+       signal->group_stop_count = 0;
 
-       for_each_thread(start, t) {
+       __for_each_thread(signal, t) {
                task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK);
                if (t != current && !(t->flags & PF_POSTCOREDUMP)) {
                        sigaddset(&t->pending.signal, SIGKILL);
@@ -391,8 +390,9 @@ static int zap_threads(struct task_struct *tsk,
 
        spin_lock_irq(&tsk->sighand->siglock);
        if (!(signal->flags & SIGNAL_GROUP_EXIT) && !signal->group_exec_task) {
+               /* Allow SIGKILL, see prepare_signal() */
                signal->core_state = core_state;
-               nr = zap_process(tsk, exit_code);
+               nr = zap_process(signal, exit_code);
                clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
                tsk->flags |= PF_DUMPCORE;
                atomic_set(&core_state->nr_threads, nr);