tty: simplify calling of put_pid.
This patch should contain no functional changes. At some point I got confused and thought put_pid could not be called while a spin lock was held. While it may be nice to avoid that to reduce lock hold times put_pid can be safely called while we hold a spin lock. This patch removes all of the complications from the code introduced by my misunderstanding, making the code a little more readable. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
f67c3627b4
commit
2a65f1d9fe
|
@ -153,8 +153,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
|
||||||
unsigned int cmd, unsigned long arg);
|
unsigned int cmd, unsigned long arg);
|
||||||
static int tty_fasync(int fd, struct file * filp, int on);
|
static int tty_fasync(int fd, struct file * filp, int on);
|
||||||
static void release_tty(struct tty_struct *tty, int idx);
|
static void release_tty(struct tty_struct *tty, int idx);
|
||||||
static struct pid *__proc_set_tty(struct task_struct *tsk,
|
static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
|
||||||
struct tty_struct *tty);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alloc_tty_struct - allocate a tty object
|
* alloc_tty_struct - allocate a tty object
|
||||||
|
@ -1532,10 +1531,9 @@ void disassociate_ctty(int on_exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
tty_pgrp = current->signal->tty_old_pgrp;
|
put_pid(current->signal->tty_old_pgrp);
|
||||||
current->signal->tty_old_pgrp = NULL;
|
current->signal->tty_old_pgrp = NULL;
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
put_pid(tty_pgrp);
|
|
||||||
|
|
||||||
mutex_lock(&tty_mutex);
|
mutex_lock(&tty_mutex);
|
||||||
/* It is possible that do_tty_hangup has free'd this tty */
|
/* It is possible that do_tty_hangup has free'd this tty */
|
||||||
|
@ -2506,7 +2504,6 @@ static int tty_open(struct inode * inode, struct file * filp)
|
||||||
int index;
|
int index;
|
||||||
dev_t device = inode->i_rdev;
|
dev_t device = inode->i_rdev;
|
||||||
unsigned short saved_flags = filp->f_flags;
|
unsigned short saved_flags = filp->f_flags;
|
||||||
struct pid *old_pgrp;
|
|
||||||
|
|
||||||
nonseekable_open(inode, filp);
|
nonseekable_open(inode, filp);
|
||||||
|
|
||||||
|
@ -2600,17 +2597,15 @@ got_driver:
|
||||||
goto retry_open;
|
goto retry_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_pgrp = NULL;
|
|
||||||
mutex_lock(&tty_mutex);
|
mutex_lock(&tty_mutex);
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
if (!noctty &&
|
if (!noctty &&
|
||||||
current->signal->leader &&
|
current->signal->leader &&
|
||||||
!current->signal->tty &&
|
!current->signal->tty &&
|
||||||
tty->session == NULL)
|
tty->session == NULL)
|
||||||
old_pgrp = __proc_set_tty(current, tty);
|
__proc_set_tty(current, tty);
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
mutex_unlock(&tty_mutex);
|
mutex_unlock(&tty_mutex);
|
||||||
put_pid(old_pgrp);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3835,9 +3830,8 @@ void proc_clear_tty(struct task_struct *p)
|
||||||
spin_unlock_irq(&p->sighand->siglock);
|
spin_unlock_irq(&p->sighand->siglock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
||||||
{
|
{
|
||||||
struct pid *old_pgrp;
|
|
||||||
if (tty) {
|
if (tty) {
|
||||||
/* We should not have a session or pgrp to here but.... */
|
/* We should not have a session or pgrp to here but.... */
|
||||||
put_pid(tty->session);
|
put_pid(tty->session);
|
||||||
|
@ -3845,21 +3839,16 @@ static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tt
|
||||||
tty->session = get_pid(task_session(tsk));
|
tty->session = get_pid(task_session(tsk));
|
||||||
tty->pgrp = get_pid(task_pgrp(tsk));
|
tty->pgrp = get_pid(task_pgrp(tsk));
|
||||||
}
|
}
|
||||||
old_pgrp = tsk->signal->tty_old_pgrp;
|
put_pid(tsk->signal->tty_old_pgrp);
|
||||||
tsk->signal->tty = tty;
|
tsk->signal->tty = tty;
|
||||||
tsk->signal->tty_old_pgrp = NULL;
|
tsk->signal->tty_old_pgrp = NULL;
|
||||||
return old_pgrp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
|
||||||
{
|
{
|
||||||
struct pid *old_pgrp;
|
|
||||||
|
|
||||||
spin_lock_irq(&tsk->sighand->siglock);
|
spin_lock_irq(&tsk->sighand->siglock);
|
||||||
old_pgrp = __proc_set_tty(tsk, tty);
|
__proc_set_tty(tsk, tty);
|
||||||
spin_unlock_irq(&tsk->sighand->siglock);
|
spin_unlock_irq(&tsk->sighand->siglock);
|
||||||
|
|
||||||
put_pid(old_pgrp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tty_struct *get_current_tty(void)
|
struct tty_struct *get_current_tty(void)
|
||||||
|
|
Loading…
Reference in New Issue