fork/exit: move tty_kref_put() outside of __cleanup_signal()
authorOleg Nesterov <oleg@redhat.com>
Wed, 26 May 2010 21:43:15 +0000 (14:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 27 May 2010 16:12:46 +0000 (09:12 -0700)
tty_kref_put() has two callsites in copy_process() paths,

1. if copy_process() suceeds it is called before we copy
   signal->tty from parent

2. otherwise it is called from __cleanup_signal() under
   bad_fork_cleanup_signal: label

In both cases tty_kref_put() is not right and unneeded because we don't
have the balancing tty_kref_get().  Fortunately, this is harmless because
this can only happen without CLONE_THREAD, and in this case signal->tty
must be NULL.

Remove tty_kref_put() from copy_process() and __cleanup_signal(), and
change another caller of __cleanup_signal(), __exit_signal(), to call
tty_kref_put() by hand.

I hope this change makes sense by itself, but it is also needed to make
->signal refcountable.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Acked-by: Roland McGrath <roland@redhat.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/exit.c
kernel/fork.c

index 4c70c37..4a72f17 100644 (file)
@@ -149,6 +149,7 @@ static void __exit_signal(struct task_struct *tsk)
                 * see account_group_exec_runtime().
                 */
                task_rq_unlock_wait(tsk);
+               tty_kref_put(sig->tty);
                __cleanup_signal(sig);
        }
 }
index 2e9cc31..b7879ef 100644 (file)
@@ -892,7 +892,6 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
 void __cleanup_signal(struct signal_struct *sig)
 {
        thread_group_cputime_free(sig);
-       tty_kref_put(sig->tty);
        kmem_cache_free(signal_cachep, sig);
 }
 
@@ -1263,7 +1262,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
                                p->nsproxy->pid_ns->child_reaper = p;
 
                        p->signal->leader_pid = pid;
-                       tty_kref_put(p->signal->tty);
                        p->signal->tty = tty_kref_get(current->signal->tty);
                        attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
                        attach_pid(p, PIDTYPE_SID, task_session(current));