]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
exit: kill unnecessary thread_group_leader() checks in exit_notify() and do_notify_pa...
authorOleg Nesterov <oleg@redhat.com>
Sun, 22 Feb 2026 15:23:37 +0000 (16:23 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 28 Mar 2026 04:19:34 +0000 (21:19 -0700)
thread_group_empty(tsk) is only possible if tsk is a group leader, and
thread_group_empty() already does the thread_group_leader() check.

So it makes no sense to check "thread_group_leader() &&
thread_group_empty()"; thread_group_empty() alone is enough.

Link: https://lkml.kernel.org/r/aZsfeegKZPZZszJh@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Kees Cook <kees@kernel.org>
Cc; Deepanshu Kartikey <kartikey406@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/exit.c
kernel/signal.c

index ede3117fa7d413a40105af85be6da21583cbaa88..1f32023d0dbe2cbe743aae0a4501e609305b976a 100644 (file)
@@ -748,14 +748,12 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
        tsk->exit_state = EXIT_ZOMBIE;
 
        if (unlikely(tsk->ptrace)) {
-               int sig = thread_group_leader(tsk) &&
-                               thread_group_empty(tsk) &&
-                               !ptrace_reparented(tsk) ?
-                       tsk->exit_signal : SIGCHLD;
+               int sig = thread_group_empty(tsk) && !ptrace_reparented(tsk)
+                         ? tsk->exit_signal : SIGCHLD;
                autoreap = do_notify_parent(tsk, sig);
        } else if (thread_group_leader(tsk)) {
                autoreap = thread_group_empty(tsk) &&
-                       do_notify_parent(tsk, tsk->exit_signal);
+                          do_notify_parent(tsk, tsk->exit_signal);
        } else {
                autoreap = true;
                /* untraced sub-thread */
index d65d0fe24bfb8c6f859ce47f36ab975308b1b598..ca23059a947dcede67b20b6e0cee6b25d2768b46 100644 (file)
@@ -2178,8 +2178,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
        /* do_notify_parent_cldstop should have been called instead.  */
        WARN_ON_ONCE(task_is_stopped_or_traced(tsk));
 
-       WARN_ON_ONCE(!tsk->ptrace &&
-              (tsk->group_leader != tsk || !thread_group_empty(tsk)));
+       WARN_ON_ONCE(!tsk->ptrace && !thread_group_empty(tsk));
 
        /* ptraced, or group-leader without sub-threads */
        do_notify_pidfd(tsk);