From: Ingo Molnar Semaphore to mutex conversion. The conversion was generated via scripts, and the result was validated automatically via a script as well. Signed-off-by: Ingo Molnar Cc: Alan Cox Cc: Russell King Signed-off-by: Andrew Morton --- drivers/char/n_tty.c | 10 +++---- drivers/char/tty_io.c | 52 ++++++++++++++++++++-------------------- drivers/char/vt.c | 14 +++++----- include/linux/tty.h | 8 +++--- kernel/exit.c | 4 +-- kernel/sys.c | 4 +-- 6 files changed, 46 insertions(+), 46 deletions(-) diff -puN drivers/char/n_tty.c~sem2mutex-tty drivers/char/n_tty.c --- 25/drivers/char/n_tty.c~sem2mutex-tty Fri Jan 13 16:11:55 2006 +++ 25-akpm/drivers/char/n_tty.c Fri Jan 13 16:11:55 2006 @@ -132,7 +132,7 @@ static void put_tty_queue(unsigned char * 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. */ @@ -1132,7 +1132,7 @@ static inline int input_available_p(stru * 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 * */ @@ -1262,11 +1262,11 @@ do_it_again: * 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; } @@ -1393,7 +1393,7 @@ do_it_again: 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)) diff -puN drivers/char/tty_io.c~sem2mutex-tty drivers/char/tty_io.c --- 25/drivers/char/tty_io.c~sem2mutex-tty Fri Jan 13 16:11:55 2006 +++ 25-akpm/drivers/char/tty_io.c Fri Jan 13 16:11:55 2006 @@ -130,7 +130,7 @@ LIST_HEAD(tty_drivers); /* linked list /* 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 */ @@ -1166,11 +1166,11 @@ 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 { @@ -1178,7 +1178,7 @@ void disassociate_ctty(int on_exit) 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; } @@ -1189,7 +1189,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; @@ -1200,7 +1200,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(); } @@ -1284,7 +1284,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; } @@ -1307,7 +1307,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; @@ -1316,7 +1316,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); @@ -1352,7 +1352,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; } @@ -1420,8 +1420,8 @@ static inline void tty_line_name(struct /* * 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, @@ -1618,7 +1618,7 @@ fast_track: 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; @@ -1815,11 +1815,11 @@ static void release_dev(struct file * fi /* 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)); - up(&tty_sem); + mutex_unlock(&tty_mutex); do_sleep = 0; if (tty_closing) { @@ -1856,7 +1856,7 @@ static void release_dev(struct file * fi * block, so it's safe to proceed with closing. */ - down(&tty_sem); + mutex_lock(&tty_mutex); if (pty_master) { if (--o_tty->count < 0) { printk(KERN_WARNING "release_dev: bad pty slave count " @@ -1870,7 +1870,7 @@ static void release_dev(struct file * fi tty->count, tty_name(tty, buf)); tty->count = 0; } - up(&tty_sem); + mutex_unlock(&tty_mutex); /* * We've decremented tty->count, so we need to remove this file @@ -2019,11 +2019,11 @@ retry_open: 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; @@ -2049,18 +2049,18 @@ retry_open: 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; @@ -2146,9 +2146,9 @@ static int ptmx_open(struct inode * inod } 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; @@ -2879,8 +2879,8 @@ static void initialize_tty_struct(struct 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); diff -puN drivers/char/vt.c~sem2mutex-tty drivers/char/vt.c --- 25/drivers/char/vt.c~sem2mutex-tty Fri Jan 13 16:11:55 2006 +++ 25-akpm/drivers/char/vt.c Fri Jan 13 16:11:55 2006 @@ -2489,7 +2489,7 @@ static int con_open(struct tty_struct *t } /* - * 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. * @@ -2497,7 +2497,7 @@ static int con_open(struct tty_struct *t */ 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; @@ -2507,15 +2507,15 @@ static void con_close(struct tty_struct 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, @@ -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) { diff -puN include/linux/tty.h~sem2mutex-tty include/linux/tty.h --- 25/include/linux/tty.h~sem2mutex-tty Fri Jan 13 16:11:55 2006 +++ 25-akpm/include/linux/tty.h Fri Jan 13 16:11:55 2006 @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -227,8 +228,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; @@ -315,8 +316,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; diff -puN kernel/exit.c~sem2mutex-tty kernel/exit.c --- 25/kernel/exit.c~sem2mutex-tty Fri Jan 13 16:11:55 2006 +++ 25-akpm/kernel/exit.c Fri Jan 13 16:11:55 2006 @@ -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); diff -puN kernel/sys.c~sem2mutex-tty kernel/sys.c --- 25/kernel/sys.c~sem2mutex-tty Fri Jan 13 16:11:55 2006 +++ 25-akpm/kernel/sys.c Fri Jan 13 16:11:55 2006 @@ -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); @@ -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; } _