goto bad_fork_cleanup_io;
        }
 
-       p->pid = pid_nr(pid);
-       p->tgid = p->pid;
-       if (clone_flags & CLONE_THREAD)
-               p->tgid = current->tgid;
-
        p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
        /*
         * Clear TID on mm_release()?
        clear_all_latency_tracing(p);
 
        /* ok, now we should be set up.. */
-       if (clone_flags & CLONE_THREAD)
+       p->pid = pid_nr(pid);
+       if (clone_flags & CLONE_THREAD) {
                p->exit_signal = -1;
-       else if (clone_flags & CLONE_PARENT)
-               p->exit_signal = current->group_leader->exit_signal;
-       else
-               p->exit_signal = (clone_flags & CSIGNAL);
+               p->group_leader = current->group_leader;
+               p->tgid = current->tgid;
+       } else {
+               if (clone_flags & CLONE_PARENT)
+                       p->exit_signal = current->group_leader->exit_signal;
+               else
+                       p->exit_signal = (clone_flags & CSIGNAL);
+               p->group_leader = p;
+               p->tgid = p->pid;
+       }
 
        p->pdeath_signal = 0;
        p->exit_state = 0;
        p->nr_dirtied_pause = 128 >> (PAGE_SHIFT - 10);
        p->dirty_paused_when = 0;
 
-       /*
-        * Ok, make it visible to the rest of the system.
-        * We dont wake it up yet.
-        */
-       p->group_leader = p;
        INIT_LIST_HEAD(&p->thread_group);
        p->task_works = NULL;
 
-       /* Need tasklist lock for parent etc handling! */
+       /*
+        * Make it visible to the rest of the system, but dont wake it up yet.
+        * Need tasklist lock for parent etc handling!
+        */
        write_lock_irq(&tasklist_lock);
 
        /* CLONE_PARENT re-uses the old parent */
                        current->signal->nr_threads++;
                        atomic_inc(¤t->signal->live);
                        atomic_inc(¤t->signal->sigcnt);
-                       p->group_leader = current->group_leader;
                        list_add_tail_rcu(&p->thread_group,
                                          &p->group_leader->thread_group);
                }