Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 23047
b: refs/heads/master
c: 70522e1
h: refs/heads/master
i:
  23045: ab5b596
  23043: 2f1b85d
  23039: 54509ae
v: v3
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Mar 23, 2006
1 parent 3784173 commit fb03cb0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d4f9af9dac4ecb75818f909168f87b441cc95653
refs/heads/master: 70522e121a521aa09bd0f4e62e1aa68708b798e1
10 changes: 5 additions & 5 deletions trunk/drivers/char/n_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty)
* We test the TTY_THROTTLED bit first so that it always
* indicates the current state. The decision about whether
* it is worth allowing more input has been taken by the caller.
* Can sleep, may be called under the atomic_read semaphore but
* Can sleep, may be called under the atomic_read_lock mutex but
* this is not guaranteed.
*/

Expand Down Expand Up @@ -1132,7 +1132,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
* buffer, and once to drain the space from the (physical) beginning of
* the buffer to head pointer.
*
* Called under the tty->atomic_read sem and with TTY_DONT_FLIP set
* Called under the tty->atomic_read_lock sem and with TTY_DONT_FLIP set
*
*/

Expand Down Expand Up @@ -1262,11 +1262,11 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
* Internal serialization of reads.
*/
if (file->f_flags & O_NONBLOCK) {
if (down_trylock(&tty->atomic_read))
if (!mutex_trylock(&tty->atomic_read_lock))
return -EAGAIN;
}
else {
if (down_interruptible(&tty->atomic_read))
if (mutex_lock_interruptible(&tty->atomic_read_lock))
return -ERESTARTSYS;
}

Expand Down Expand Up @@ -1393,7 +1393,7 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
timeout = time;
}
clear_bit(TTY_DONT_FLIP, &tty->flags);
up(&tty->atomic_read);
mutex_unlock(&tty->atomic_read_lock);
remove_wait_queue(&tty->read_wait, &wait);

if (!waitqueue_active(&tty->read_wait))
Expand Down
50 changes: 25 additions & 25 deletions trunk/drivers/char/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */

/* Semaphore to protect creating and releasing a tty. This is shared with
vt.c for deeply disgusting hack reasons */
DECLARE_MUTEX(tty_sem);
DEFINE_MUTEX(tty_mutex);

#ifdef CONFIG_UNIX98_PTYS
extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
Expand Down Expand Up @@ -1188,19 +1188,19 @@ void disassociate_ctty(int on_exit)

lock_kernel();

down(&tty_sem);
mutex_lock(&tty_mutex);
tty = current->signal->tty;
if (tty) {
tty_pgrp = tty->pgrp;
up(&tty_sem);
mutex_unlock(&tty_mutex);
if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
tty_vhangup(tty);
} else {
if (current->signal->tty_old_pgrp) {
kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
}
up(&tty_sem);
mutex_unlock(&tty_mutex);
unlock_kernel();
return;
}
Expand All @@ -1211,7 +1211,7 @@ void disassociate_ctty(int on_exit)
}

/* Must lock changes to tty_old_pgrp */
down(&tty_sem);
mutex_lock(&tty_mutex);
current->signal->tty_old_pgrp = 0;
tty->session = 0;
tty->pgrp = -1;
Expand All @@ -1222,7 +1222,7 @@ void disassociate_ctty(int on_exit)
p->signal->tty = NULL;
} while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
read_unlock(&tasklist_lock);
up(&tty_sem);
mutex_unlock(&tty_mutex);
unlock_kernel();
}

Expand Down Expand Up @@ -1306,7 +1306,7 @@ static inline ssize_t do_tty_write(
ssize_t ret = 0, written = 0;
unsigned int chunk;

if (down_interruptible(&tty->atomic_write)) {
if (mutex_lock_interruptible(&tty->atomic_write_lock)) {
return -ERESTARTSYS;
}

Expand All @@ -1329,7 +1329,7 @@ static inline ssize_t do_tty_write(
if (count < chunk)
chunk = count;

/* write_buf/write_cnt is protected by the atomic_write semaphore */
/* write_buf/write_cnt is protected by the atomic_write_lock mutex */
if (tty->write_cnt < chunk) {
unsigned char *buf;

Expand All @@ -1338,7 +1338,7 @@ static inline ssize_t do_tty_write(

buf = kmalloc(chunk, GFP_KERNEL);
if (!buf) {
up(&tty->atomic_write);
mutex_unlock(&tty->atomic_write_lock);
return -ENOMEM;
}
kfree(tty->write_buf);
Expand Down Expand Up @@ -1374,7 +1374,7 @@ static inline ssize_t do_tty_write(
inode->i_mtime = current_fs_time(inode->i_sb);
ret = written;
}
up(&tty->atomic_write);
mutex_unlock(&tty->atomic_write_lock);
return ret;
}

Expand Down Expand Up @@ -1442,8 +1442,8 @@ static inline void tty_line_name(struct tty_driver *driver, int index, char *p)

/*
* WSH 06/09/97: Rewritten to remove races and properly clean up after a
* failed open. The new code protects the open with a semaphore, so it's
* really quite straightforward. The semaphore locking can probably be
* failed open. The new code protects the open with a mutex, so it's
* really quite straightforward. The mutex locking can probably be
* relaxed for the (most common) case of reopening a tty.
*/
static int init_dev(struct tty_driver *driver, int idx,
Expand Down Expand Up @@ -1640,7 +1640,7 @@ static int init_dev(struct tty_driver *driver, int idx,
success:
*ret_tty = tty;

/* All paths come through here to release the semaphore */
/* All paths come through here to release the mutex */
end_init:
return retval;

Expand Down Expand Up @@ -1837,7 +1837,7 @@ static void release_dev(struct file * filp)
/* Guard against races with tty->count changes elsewhere and
opens on /dev/tty */

down(&tty_sem);
mutex_lock(&tty_mutex);
tty_closing = tty->count <= 1;
o_tty_closing = o_tty &&
(o_tty->count <= (pty_master ? 1 : 0));
Expand Down Expand Up @@ -1868,7 +1868,7 @@ static void release_dev(struct file * filp)

printk(KERN_WARNING "release_dev: %s: read/write wait queue "
"active!\n", tty_name(tty, buf));
up(&tty_sem);
mutex_unlock(&tty_mutex);
schedule();
}

Expand Down Expand Up @@ -1934,7 +1934,7 @@ static void release_dev(struct file * filp)
read_unlock(&tasklist_lock);
}

up(&tty_sem);
mutex_unlock(&tty_mutex);

/* check whether both sides are closing ... */
if (!tty_closing || (o_tty && !o_tty_closing))
Expand Down Expand Up @@ -2040,11 +2040,11 @@ static int tty_open(struct inode * inode, struct file * filp)
index = -1;
retval = 0;

down(&tty_sem);
mutex_lock(&tty_mutex);

if (device == MKDEV(TTYAUX_MAJOR,0)) {
if (!current->signal->tty) {
up(&tty_sem);
mutex_unlock(&tty_mutex);
return -ENXIO;
}
driver = current->signal->tty->driver;
Expand All @@ -2070,18 +2070,18 @@ static int tty_open(struct inode * inode, struct file * filp)
noctty = 1;
goto got_driver;
}
up(&tty_sem);
mutex_unlock(&tty_mutex);
return -ENODEV;
}

driver = get_tty_driver(device, &index);
if (!driver) {
up(&tty_sem);
mutex_unlock(&tty_mutex);
return -ENODEV;
}
got_driver:
retval = init_dev(driver, index, &tty);
up(&tty_sem);
mutex_unlock(&tty_mutex);
if (retval)
return retval;

Expand Down Expand Up @@ -2167,9 +2167,9 @@ static int ptmx_open(struct inode * inode, struct file * filp)
}
up(&allocated_ptys_lock);

down(&tty_sem);
mutex_lock(&tty_mutex);
retval = init_dev(ptm_driver, index, &tty);
up(&tty_sem);
mutex_unlock(&tty_mutex);

if (retval)
goto out;
Expand Down Expand Up @@ -2915,8 +2915,8 @@ static void initialize_tty_struct(struct tty_struct *tty)
init_waitqueue_head(&tty->write_wait);
init_waitqueue_head(&tty->read_wait);
INIT_WORK(&tty->hangup_work, do_tty_hangup, tty);
sema_init(&tty->atomic_read, 1);
sema_init(&tty->atomic_write, 1);
mutex_init(&tty->atomic_read_lock);
mutex_init(&tty->atomic_write_lock);
spin_lock_init(&tty->read_lock);
INIT_LIST_HEAD(&tty->tty_files);
INIT_WORK(&tty->SAK_work, NULL, NULL);
Expand Down
14 changes: 7 additions & 7 deletions trunk/drivers/char/vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2489,15 +2489,15 @@ static int con_open(struct tty_struct *tty, struct file *filp)
}

/*
* We take tty_sem in here to prevent another thread from coming in via init_dev
* We take tty_mutex in here to prevent another thread from coming in via init_dev
* and taking a ref against the tty while we're in the process of forgetting
* about it and cleaning things up.
*
* This is because vcs_remove_devfs() can sleep and will drop the BKL.
*/
static void con_close(struct tty_struct *tty, struct file *filp)
{
down(&tty_sem);
mutex_lock(&tty_mutex);
acquire_console_sem();
if (tty && tty->count == 1) {
struct vc_data *vc = tty->driver_data;
Expand All @@ -2507,15 +2507,15 @@ static void con_close(struct tty_struct *tty, struct file *filp)
tty->driver_data = NULL;
release_console_sem();
vcs_remove_devfs(tty);
up(&tty_sem);
mutex_unlock(&tty_mutex);
/*
* tty_sem is released, but we still hold BKL, so there is
* tty_mutex is released, but we still hold BKL, so there is
* still exclusion against init_dev()
*/
return;
}
release_console_sem();
up(&tty_sem);
mutex_unlock(&tty_mutex);
}

static void vc_init(struct vc_data *vc, unsigned int rows,
Expand Down Expand Up @@ -2869,9 +2869,9 @@ void unblank_screen(void)
}

/*
* We defer the timer blanking to work queue so it can take the console semaphore
* We defer the timer blanking to work queue so it can take the console mutex
* (console operations can still happen at irq time, but only from printk which
* has the console semaphore. Not perfect yet, but better than no locking
* has the console mutex. Not perfect yet, but better than no locking
*/
static void blank_screen_t(unsigned long dummy)
{
Expand Down
8 changes: 4 additions & 4 deletions trunk/include/linux/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/tty_driver.h>
#include <linux/tty_ldisc.h>
#include <linux/screen_info.h>
#include <linux/mutex.h>

#include <asm/system.h>

Expand Down Expand Up @@ -231,8 +232,8 @@ struct tty_struct {
int canon_data;
unsigned long canon_head;
unsigned int canon_column;
struct semaphore atomic_read;
struct semaphore atomic_write;
struct mutex atomic_read_lock;
struct mutex atomic_write_lock;
unsigned char *write_buf;
int write_cnt;
spinlock_t read_lock;
Expand Down Expand Up @@ -319,8 +320,7 @@ extern void tty_ldisc_put(int);
extern void tty_wakeup(struct tty_struct *tty);
extern void tty_ldisc_flush(struct tty_struct *tty);

struct semaphore;
extern struct semaphore tty_sem;
extern struct mutex tty_mutex;

/* n_tty.c */
extern struct tty_ldisc tty_ldisc_N_TTY;
Expand Down
4 changes: 2 additions & 2 deletions trunk/kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ void daemonize(const char *name, ...)
exit_mm(current);

set_special_pids(1, 1);
down(&tty_sem);
mutex_lock(&tty_mutex);
current->signal->tty = NULL;
up(&tty_sem);
mutex_unlock(&tty_mutex);

/* Block and flush all signals */
sigfillset(&blocked);
Expand Down
4 changes: 2 additions & 2 deletions trunk/kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ asmlinkage long sys_setsid(void)
struct pid *pid;
int err = -EPERM;

down(&tty_sem);
mutex_lock(&tty_mutex);
write_lock_irq(&tasklist_lock);

pid = find_pid(PIDTYPE_PGID, group_leader->pid);
Expand All @@ -1241,7 +1241,7 @@ asmlinkage long sys_setsid(void)
err = process_group(group_leader);
out:
write_unlock_irq(&tasklist_lock);
up(&tty_sem);
mutex_unlock(&tty_mutex);
return err;
}

Expand Down

0 comments on commit fb03cb0

Please sign in to comment.