Commit 70522e12 authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds

[PATCH] sem2mutex: tty

Semaphore to mutex conversion.

The conversion was generated via scripts, and the result was validated
automatically via a script as well.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d4f9af9d
...@@ -132,7 +132,7 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty) ...@@ -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 * We test the TTY_THROTTLED bit first so that it always
* indicates the current state. The decision about whether * indicates the current state. The decision about whether
* it is worth allowing more input has been taken by the caller. * 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. * this is not guaranteed.
*/ */
...@@ -1132,7 +1132,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt) ...@@ -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 * buffer, and once to drain the space from the (physical) beginning of
* the buffer to head pointer. * 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
* *
*/ */
...@@ -1262,11 +1262,11 @@ do_it_again: ...@@ -1262,11 +1262,11 @@ do_it_again:
* Internal serialization of reads. * Internal serialization of reads.
*/ */
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
if (down_trylock(&tty->atomic_read)) if (!mutex_trylock(&tty->atomic_read_lock))
return -EAGAIN; return -EAGAIN;
} }
else { else {
if (down_interruptible(&tty->atomic_read)) if (mutex_lock_interruptible(&tty->atomic_read_lock))
return -ERESTARTSYS; return -ERESTARTSYS;
} }
...@@ -1393,7 +1393,7 @@ do_it_again: ...@@ -1393,7 +1393,7 @@ do_it_again:
timeout = time; timeout = time;
} }
clear_bit(TTY_DONT_FLIP, &tty->flags); clear_bit(TTY_DONT_FLIP, &tty->flags);
up(&tty->atomic_read); mutex_unlock(&tty->atomic_read_lock);
remove_wait_queue(&tty->read_wait, &wait); remove_wait_queue(&tty->read_wait, &wait);
if (!waitqueue_active(&tty->read_wait)) if (!waitqueue_active(&tty->read_wait))
......
...@@ -130,7 +130,7 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */ ...@@ -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 /* Semaphore to protect creating and releasing a tty. This is shared with
vt.c for deeply disgusting hack reasons */ vt.c for deeply disgusting hack reasons */
DECLARE_MUTEX(tty_sem); DEFINE_MUTEX(tty_mutex);
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
...@@ -1188,11 +1188,11 @@ void disassociate_ctty(int on_exit) ...@@ -1188,11 +1188,11 @@ void disassociate_ctty(int on_exit)
lock_kernel(); lock_kernel();
down(&tty_sem); mutex_lock(&tty_mutex);
tty = current->signal->tty; tty = current->signal->tty;
if (tty) { if (tty) {
tty_pgrp = tty->pgrp; tty_pgrp = tty->pgrp;
up(&tty_sem); mutex_unlock(&tty_mutex);
if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
tty_vhangup(tty); tty_vhangup(tty);
} else { } else {
...@@ -1200,7 +1200,7 @@ void disassociate_ctty(int on_exit) ...@@ -1200,7 +1200,7 @@ void disassociate_ctty(int on_exit)
kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
} }
up(&tty_sem); mutex_unlock(&tty_mutex);
unlock_kernel(); unlock_kernel();
return; return;
} }
...@@ -1211,7 +1211,7 @@ void disassociate_ctty(int on_exit) ...@@ -1211,7 +1211,7 @@ void disassociate_ctty(int on_exit)
} }
/* Must lock changes to tty_old_pgrp */ /* Must lock changes to tty_old_pgrp */
down(&tty_sem); mutex_lock(&tty_mutex);
current->signal->tty_old_pgrp = 0; current->signal->tty_old_pgrp = 0;
tty->session = 0; tty->session = 0;
tty->pgrp = -1; tty->pgrp = -1;
...@@ -1222,7 +1222,7 @@ void disassociate_ctty(int on_exit) ...@@ -1222,7 +1222,7 @@ void disassociate_ctty(int on_exit)
p->signal->tty = NULL; p->signal->tty = NULL;
} while_each_task_pid(current->signal->session, PIDTYPE_SID, p); } while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
up(&tty_sem); mutex_unlock(&tty_mutex);
unlock_kernel(); unlock_kernel();
} }
...@@ -1306,7 +1306,7 @@ static inline ssize_t do_tty_write( ...@@ -1306,7 +1306,7 @@ static inline ssize_t do_tty_write(
ssize_t ret = 0, written = 0; ssize_t ret = 0, written = 0;
unsigned int chunk; unsigned int chunk;
if (down_interruptible(&tty->atomic_write)) { if (mutex_lock_interruptible(&tty->atomic_write_lock)) {
return -ERESTARTSYS; return -ERESTARTSYS;
} }
...@@ -1329,7 +1329,7 @@ static inline ssize_t do_tty_write( ...@@ -1329,7 +1329,7 @@ static inline ssize_t do_tty_write(
if (count < chunk) if (count < chunk)
chunk = count; 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) { if (tty->write_cnt < chunk) {
unsigned char *buf; unsigned char *buf;
...@@ -1338,7 +1338,7 @@ static inline ssize_t do_tty_write( ...@@ -1338,7 +1338,7 @@ static inline ssize_t do_tty_write(
buf = kmalloc(chunk, GFP_KERNEL); buf = kmalloc(chunk, GFP_KERNEL);
if (!buf) { if (!buf) {
up(&tty->atomic_write); mutex_unlock(&tty->atomic_write_lock);
return -ENOMEM; return -ENOMEM;
} }
kfree(tty->write_buf); kfree(tty->write_buf);
...@@ -1374,7 +1374,7 @@ static inline ssize_t do_tty_write( ...@@ -1374,7 +1374,7 @@ static inline ssize_t do_tty_write(
inode->i_mtime = current_fs_time(inode->i_sb); inode->i_mtime = current_fs_time(inode->i_sb);
ret = written; ret = written;
} }
up(&tty->atomic_write); mutex_unlock(&tty->atomic_write_lock);
return ret; return ret;
} }
...@@ -1442,8 +1442,8 @@ static inline void tty_line_name(struct tty_driver *driver, int index, char *p) ...@@ -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 * 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 * failed open. The new code protects the open with a mutex, so it's
* really quite straightforward. The semaphore locking can probably be * really quite straightforward. The mutex locking can probably be
* relaxed for the (most common) case of reopening a tty. * relaxed for the (most common) case of reopening a tty.
*/ */
static int init_dev(struct tty_driver *driver, int idx, static int init_dev(struct tty_driver *driver, int idx,
...@@ -1640,7 +1640,7 @@ fast_track: ...@@ -1640,7 +1640,7 @@ fast_track:
success: success:
*ret_tty = tty; *ret_tty = tty;
/* All paths come through here to release the semaphore */ /* All paths come through here to release the mutex */
end_init: end_init:
return retval; return retval;
...@@ -1837,7 +1837,7 @@ static void release_dev(struct file * filp) ...@@ -1837,7 +1837,7 @@ static void release_dev(struct file * filp)
/* Guard against races with tty->count changes elsewhere and /* Guard against races with tty->count changes elsewhere and
opens on /dev/tty */ opens on /dev/tty */
down(&tty_sem); mutex_lock(&tty_mutex);
tty_closing = tty->count <= 1; tty_closing = tty->count <= 1;
o_tty_closing = o_tty && o_tty_closing = o_tty &&
(o_tty->count <= (pty_master ? 1 : 0)); (o_tty->count <= (pty_master ? 1 : 0));
...@@ -1868,7 +1868,7 @@ static void release_dev(struct file * filp) ...@@ -1868,7 +1868,7 @@ static void release_dev(struct file * filp)
printk(KERN_WARNING "release_dev: %s: read/write wait queue " printk(KERN_WARNING "release_dev: %s: read/write wait queue "
"active!\n", tty_name(tty, buf)); "active!\n", tty_name(tty, buf));
up(&tty_sem); mutex_unlock(&tty_mutex);
schedule(); schedule();
} }
...@@ -1934,7 +1934,7 @@ static void release_dev(struct file * filp) ...@@ -1934,7 +1934,7 @@ static void release_dev(struct file * filp)
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
} }
up(&tty_sem); mutex_unlock(&tty_mutex);
/* check whether both sides are closing ... */ /* check whether both sides are closing ... */
if (!tty_closing || (o_tty && !o_tty_closing)) if (!tty_closing || (o_tty && !o_tty_closing))
...@@ -2040,11 +2040,11 @@ retry_open: ...@@ -2040,11 +2040,11 @@ retry_open:
index = -1; index = -1;
retval = 0; retval = 0;
down(&tty_sem); mutex_lock(&tty_mutex);
if (device == MKDEV(TTYAUX_MAJOR,0)) { if (device == MKDEV(TTYAUX_MAJOR,0)) {
if (!current->signal->tty) { if (!current->signal->tty) {
up(&tty_sem); mutex_unlock(&tty_mutex);
return -ENXIO; return -ENXIO;
} }
driver = current->signal->tty->driver; driver = current->signal->tty->driver;
...@@ -2070,18 +2070,18 @@ retry_open: ...@@ -2070,18 +2070,18 @@ retry_open:
noctty = 1; noctty = 1;
goto got_driver; goto got_driver;
} }
up(&tty_sem); mutex_unlock(&tty_mutex);
return -ENODEV; return -ENODEV;
} }
driver = get_tty_driver(device, &index); driver = get_tty_driver(device, &index);
if (!driver) { if (!driver) {
up(&tty_sem); mutex_unlock(&tty_mutex);
return -ENODEV; return -ENODEV;
} }
got_driver: got_driver:
retval = init_dev(driver, index, &tty); retval = init_dev(driver, index, &tty);
up(&tty_sem); mutex_unlock(&tty_mutex);
if (retval) if (retval)
return retval; return retval;
...@@ -2167,9 +2167,9 @@ static int ptmx_open(struct inode * inode, struct file * filp) ...@@ -2167,9 +2167,9 @@ static int ptmx_open(struct inode * inode, struct file * filp)
} }
up(&allocated_ptys_lock); up(&allocated_ptys_lock);
down(&tty_sem); mutex_lock(&tty_mutex);
retval = init_dev(ptm_driver, index, &tty); retval = init_dev(ptm_driver, index, &tty);
up(&tty_sem); mutex_unlock(&tty_mutex);
if (retval) if (retval)
goto out; goto out;
...@@ -2915,8 +2915,8 @@ static void initialize_tty_struct(struct tty_struct *tty) ...@@ -2915,8 +2915,8 @@ static void initialize_tty_struct(struct tty_struct *tty)
init_waitqueue_head(&tty->write_wait); init_waitqueue_head(&tty->write_wait);
init_waitqueue_head(&tty->read_wait); init_waitqueue_head(&tty->read_wait);
INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); INIT_WORK(&tty->hangup_work, do_tty_hangup, tty);
sema_init(&tty->atomic_read, 1); mutex_init(&tty->atomic_read_lock);
sema_init(&tty->atomic_write, 1); mutex_init(&tty->atomic_write_lock);
spin_lock_init(&tty->read_lock); spin_lock_init(&tty->read_lock);
INIT_LIST_HEAD(&tty->tty_files); INIT_LIST_HEAD(&tty->tty_files);
INIT_WORK(&tty->SAK_work, NULL, NULL); INIT_WORK(&tty->SAK_work, NULL, NULL);
......
...@@ -2489,7 +2489,7 @@ static int con_open(struct tty_struct *tty, struct file *filp) ...@@ -2489,7 +2489,7 @@ 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 * and taking a ref against the tty while we're in the process of forgetting
* about it and cleaning things up. * about it and cleaning things up.
* *
...@@ -2497,7 +2497,7 @@ static int con_open(struct tty_struct *tty, struct file *filp) ...@@ -2497,7 +2497,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
*/ */
static void con_close(struct tty_struct *tty, struct file *filp) static void con_close(struct tty_struct *tty, struct file *filp)
{ {
down(&tty_sem); mutex_lock(&tty_mutex);
acquire_console_sem(); acquire_console_sem();
if (tty && tty->count == 1) { if (tty && tty->count == 1) {
struct vc_data *vc = tty->driver_data; struct vc_data *vc = tty->driver_data;
...@@ -2507,15 +2507,15 @@ static void con_close(struct tty_struct *tty, struct file *filp) ...@@ -2507,15 +2507,15 @@ static void con_close(struct tty_struct *tty, struct file *filp)
tty->driver_data = NULL; tty->driver_data = NULL;
release_console_sem(); release_console_sem();
vcs_remove_devfs(tty); 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() * still exclusion against init_dev()
*/ */
return; return;
} }
release_console_sem(); release_console_sem();
up(&tty_sem); mutex_unlock(&tty_mutex);
} }
static void vc_init(struct vc_data *vc, unsigned int rows, static void vc_init(struct vc_data *vc, unsigned int rows,
...@@ -2869,9 +2869,9 @@ void unblank_screen(void) ...@@ -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 * (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) static void blank_screen_t(unsigned long dummy)
{ {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/tty_driver.h> #include <linux/tty_driver.h>
#include <linux/tty_ldisc.h> #include <linux/tty_ldisc.h>
#include <linux/screen_info.h> #include <linux/screen_info.h>
#include <linux/mutex.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -231,8 +232,8 @@ struct tty_struct { ...@@ -231,8 +232,8 @@ struct tty_struct {
int canon_data; int canon_data;
unsigned long canon_head; unsigned long canon_head;
unsigned int canon_column; unsigned int canon_column;
struct semaphore atomic_read; struct mutex atomic_read_lock;
struct semaphore atomic_write; struct mutex atomic_write_lock;
unsigned char *write_buf; unsigned char *write_buf;
int write_cnt; int write_cnt;
spinlock_t read_lock; spinlock_t read_lock;
...@@ -319,8 +320,7 @@ extern void tty_ldisc_put(int); ...@@ -319,8 +320,7 @@ extern void tty_ldisc_put(int);
extern void tty_wakeup(struct tty_struct *tty); extern void tty_wakeup(struct tty_struct *tty);
extern void tty_ldisc_flush(struct tty_struct *tty); extern void tty_ldisc_flush(struct tty_struct *tty);
struct semaphore; extern struct mutex tty_mutex;
extern struct semaphore tty_sem;
/* n_tty.c */ /* n_tty.c */
extern struct tty_ldisc tty_ldisc_N_TTY; extern struct tty_ldisc tty_ldisc_N_TTY;
......
...@@ -345,9 +345,9 @@ void daemonize(const char *name, ...) ...@@ -345,9 +345,9 @@ void daemonize(const char *name, ...)
exit_mm(current); exit_mm(current);
set_special_pids(1, 1); set_special_pids(1, 1);
down(&tty_sem); mutex_lock(&tty_mutex);
current->signal->tty = NULL; current->signal->tty = NULL;
up(&tty_sem); mutex_unlock(&tty_mutex);
/* Block and flush all signals */ /* Block and flush all signals */
sigfillset(&blocked); sigfillset(&blocked);
......
...@@ -1227,7 +1227,7 @@ asmlinkage long sys_setsid(void) ...@@ -1227,7 +1227,7 @@ asmlinkage long sys_setsid(void)
struct pid *pid; struct pid *pid;
int err = -EPERM; int err = -EPERM;
down(&tty_sem); mutex_lock(&tty_mutex);
write_lock_irq(&tasklist_lock); write_lock_irq(&tasklist_lock);
pid = find_pid(PIDTYPE_PGID, group_leader->pid); pid = find_pid(PIDTYPE_PGID, group_leader->pid);
...@@ -1241,7 +1241,7 @@ asmlinkage long sys_setsid(void) ...@@ -1241,7 +1241,7 @@ asmlinkage long sys_setsid(void)
err = process_group(group_leader); err = process_group(group_leader);
out: out:
write_unlock_irq(&tasklist_lock); write_unlock_irq(&tasklist_lock);
up(&tty_sem); mutex_unlock(&tty_mutex);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment