diff options
Diffstat (limited to 'drivers/char/tty_io.c')
-rw-r--r-- | drivers/char/tty_io.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 53d3d066554e..76592ee1fb38 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -130,7 +130,7 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */ | |||
130 | 130 | ||
131 | /* Semaphore to protect creating and releasing a tty. This is shared with | 131 | /* Semaphore to protect creating and releasing a tty. This is shared with |
132 | vt.c for deeply disgusting hack reasons */ | 132 | vt.c for deeply disgusting hack reasons */ |
133 | DECLARE_MUTEX(tty_sem); | 133 | DEFINE_MUTEX(tty_mutex); |
134 | 134 | ||
135 | #ifdef CONFIG_UNIX98_PTYS | 135 | #ifdef CONFIG_UNIX98_PTYS |
136 | extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ | 136 | extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ |
@@ -1188,11 +1188,11 @@ void disassociate_ctty(int on_exit) | |||
1188 | 1188 | ||
1189 | lock_kernel(); | 1189 | lock_kernel(); |
1190 | 1190 | ||
1191 | down(&tty_sem); | 1191 | mutex_lock(&tty_mutex); |
1192 | tty = current->signal->tty; | 1192 | tty = current->signal->tty; |
1193 | if (tty) { | 1193 | if (tty) { |
1194 | tty_pgrp = tty->pgrp; | 1194 | tty_pgrp = tty->pgrp; |
1195 | up(&tty_sem); | 1195 | mutex_unlock(&tty_mutex); |
1196 | if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) | 1196 | if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) |
1197 | tty_vhangup(tty); | 1197 | tty_vhangup(tty); |
1198 | } else { | 1198 | } else { |
@@ -1200,7 +1200,7 @@ void disassociate_ctty(int on_exit) | |||
1200 | kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); | 1200 | kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); |
1201 | kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); | 1201 | kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); |
1202 | } | 1202 | } |
1203 | up(&tty_sem); | 1203 | mutex_unlock(&tty_mutex); |
1204 | unlock_kernel(); | 1204 | unlock_kernel(); |
1205 | return; | 1205 | return; |
1206 | } | 1206 | } |
@@ -1211,7 +1211,7 @@ void disassociate_ctty(int on_exit) | |||
1211 | } | 1211 | } |
1212 | 1212 | ||
1213 | /* Must lock changes to tty_old_pgrp */ | 1213 | /* Must lock changes to tty_old_pgrp */ |
1214 | down(&tty_sem); | 1214 | mutex_lock(&tty_mutex); |
1215 | current->signal->tty_old_pgrp = 0; | 1215 | current->signal->tty_old_pgrp = 0; |
1216 | tty->session = 0; | 1216 | tty->session = 0; |
1217 | tty->pgrp = -1; | 1217 | tty->pgrp = -1; |
@@ -1222,7 +1222,7 @@ void disassociate_ctty(int on_exit) | |||
1222 | p->signal->tty = NULL; | 1222 | p->signal->tty = NULL; |
1223 | } while_each_task_pid(current->signal->session, PIDTYPE_SID, p); | 1223 | } while_each_task_pid(current->signal->session, PIDTYPE_SID, p); |
1224 | read_unlock(&tasklist_lock); | 1224 | read_unlock(&tasklist_lock); |
1225 | up(&tty_sem); | 1225 | mutex_unlock(&tty_mutex); |
1226 | unlock_kernel(); | 1226 | unlock_kernel(); |
1227 | } | 1227 | } |
1228 | 1228 | ||
@@ -1306,7 +1306,7 @@ static inline ssize_t do_tty_write( | |||
1306 | ssize_t ret = 0, written = 0; | 1306 | ssize_t ret = 0, written = 0; |
1307 | unsigned int chunk; | 1307 | unsigned int chunk; |
1308 | 1308 | ||
1309 | if (down_interruptible(&tty->atomic_write)) { | 1309 | if (mutex_lock_interruptible(&tty->atomic_write_lock)) { |
1310 | return -ERESTARTSYS; | 1310 | return -ERESTARTSYS; |
1311 | } | 1311 | } |
1312 | 1312 | ||
@@ -1329,7 +1329,7 @@ static inline ssize_t do_tty_write( | |||
1329 | if (count < chunk) | 1329 | if (count < chunk) |
1330 | chunk = count; | 1330 | chunk = count; |
1331 | 1331 | ||
1332 | /* write_buf/write_cnt is protected by the atomic_write semaphore */ | 1332 | /* write_buf/write_cnt is protected by the atomic_write_lock mutex */ |
1333 | if (tty->write_cnt < chunk) { | 1333 | if (tty->write_cnt < chunk) { |
1334 | unsigned char *buf; | 1334 | unsigned char *buf; |
1335 | 1335 | ||
@@ -1338,7 +1338,7 @@ static inline ssize_t do_tty_write( | |||
1338 | 1338 | ||
1339 | buf = kmalloc(chunk, GFP_KERNEL); | 1339 | buf = kmalloc(chunk, GFP_KERNEL); |
1340 | if (!buf) { | 1340 | if (!buf) { |
1341 | up(&tty->atomic_write); | 1341 | mutex_unlock(&tty->atomic_write_lock); |
1342 | return -ENOMEM; | 1342 | return -ENOMEM; |
1343 | } | 1343 | } |
1344 | kfree(tty->write_buf); | 1344 | kfree(tty->write_buf); |
@@ -1374,7 +1374,7 @@ static inline ssize_t do_tty_write( | |||
1374 | inode->i_mtime = current_fs_time(inode->i_sb); | 1374 | inode->i_mtime = current_fs_time(inode->i_sb); |
1375 | ret = written; | 1375 | ret = written; |
1376 | } | 1376 | } |
1377 | up(&tty->atomic_write); | 1377 | mutex_unlock(&tty->atomic_write_lock); |
1378 | return ret; | 1378 | return ret; |
1379 | } | 1379 | } |
1380 | 1380 | ||
@@ -1442,8 +1442,8 @@ static inline void tty_line_name(struct tty_driver *driver, int index, char *p) | |||
1442 | 1442 | ||
1443 | /* | 1443 | /* |
1444 | * WSH 06/09/97: Rewritten to remove races and properly clean up after a | 1444 | * WSH 06/09/97: Rewritten to remove races and properly clean up after a |
1445 | * failed open. The new code protects the open with a semaphore, so it's | 1445 | * failed open. The new code protects the open with a mutex, so it's |
1446 | * really quite straightforward. The semaphore locking can probably be | 1446 | * really quite straightforward. The mutex locking can probably be |
1447 | * relaxed for the (most common) case of reopening a tty. | 1447 | * relaxed for the (most common) case of reopening a tty. |
1448 | */ | 1448 | */ |
1449 | static int init_dev(struct tty_driver *driver, int idx, | 1449 | static int init_dev(struct tty_driver *driver, int idx, |
@@ -1640,7 +1640,7 @@ fast_track: | |||
1640 | success: | 1640 | success: |
1641 | *ret_tty = tty; | 1641 | *ret_tty = tty; |
1642 | 1642 | ||
1643 | /* All paths come through here to release the semaphore */ | 1643 | /* All paths come through here to release the mutex */ |
1644 | end_init: | 1644 | end_init: |
1645 | return retval; | 1645 | return retval; |
1646 | 1646 | ||
@@ -1837,7 +1837,7 @@ static void release_dev(struct file * filp) | |||
1837 | /* Guard against races with tty->count changes elsewhere and | 1837 | /* Guard against races with tty->count changes elsewhere and |
1838 | opens on /dev/tty */ | 1838 | opens on /dev/tty */ |
1839 | 1839 | ||
1840 | down(&tty_sem); | 1840 | mutex_lock(&tty_mutex); |
1841 | tty_closing = tty->count <= 1; | 1841 | tty_closing = tty->count <= 1; |
1842 | o_tty_closing = o_tty && | 1842 | o_tty_closing = o_tty && |
1843 | (o_tty->count <= (pty_master ? 1 : 0)); | 1843 | (o_tty->count <= (pty_master ? 1 : 0)); |
@@ -1868,7 +1868,7 @@ static void release_dev(struct file * filp) | |||
1868 | 1868 | ||
1869 | printk(KERN_WARNING "release_dev: %s: read/write wait queue " | 1869 | printk(KERN_WARNING "release_dev: %s: read/write wait queue " |
1870 | "active!\n", tty_name(tty, buf)); | 1870 | "active!\n", tty_name(tty, buf)); |
1871 | up(&tty_sem); | 1871 | mutex_unlock(&tty_mutex); |
1872 | schedule(); | 1872 | schedule(); |
1873 | } | 1873 | } |
1874 | 1874 | ||
@@ -1934,7 +1934,7 @@ static void release_dev(struct file * filp) | |||
1934 | read_unlock(&tasklist_lock); | 1934 | read_unlock(&tasklist_lock); |
1935 | } | 1935 | } |
1936 | 1936 | ||
1937 | up(&tty_sem); | 1937 | mutex_unlock(&tty_mutex); |
1938 | 1938 | ||
1939 | /* check whether both sides are closing ... */ | 1939 | /* check whether both sides are closing ... */ |
1940 | if (!tty_closing || (o_tty && !o_tty_closing)) | 1940 | if (!tty_closing || (o_tty && !o_tty_closing)) |
@@ -2040,11 +2040,11 @@ retry_open: | |||
2040 | index = -1; | 2040 | index = -1; |
2041 | retval = 0; | 2041 | retval = 0; |
2042 | 2042 | ||
2043 | down(&tty_sem); | 2043 | mutex_lock(&tty_mutex); |
2044 | 2044 | ||
2045 | if (device == MKDEV(TTYAUX_MAJOR,0)) { | 2045 | if (device == MKDEV(TTYAUX_MAJOR,0)) { |
2046 | if (!current->signal->tty) { | 2046 | if (!current->signal->tty) { |
2047 | up(&tty_sem); | 2047 | mutex_unlock(&tty_mutex); |
2048 | return -ENXIO; | 2048 | return -ENXIO; |
2049 | } | 2049 | } |
2050 | driver = current->signal->tty->driver; | 2050 | driver = current->signal->tty->driver; |
@@ -2070,18 +2070,18 @@ retry_open: | |||
2070 | noctty = 1; | 2070 | noctty = 1; |
2071 | goto got_driver; | 2071 | goto got_driver; |
2072 | } | 2072 | } |
2073 | up(&tty_sem); | 2073 | mutex_unlock(&tty_mutex); |
2074 | return -ENODEV; | 2074 | return -ENODEV; |
2075 | } | 2075 | } |
2076 | 2076 | ||
2077 | driver = get_tty_driver(device, &index); | 2077 | driver = get_tty_driver(device, &index); |
2078 | if (!driver) { | 2078 | if (!driver) { |
2079 | up(&tty_sem); | 2079 | mutex_unlock(&tty_mutex); |
2080 | return -ENODEV; | 2080 | return -ENODEV; |
2081 | } | 2081 | } |
2082 | got_driver: | 2082 | got_driver: |
2083 | retval = init_dev(driver, index, &tty); | 2083 | retval = init_dev(driver, index, &tty); |
2084 | up(&tty_sem); | 2084 | mutex_unlock(&tty_mutex); |
2085 | if (retval) | 2085 | if (retval) |
2086 | return retval; | 2086 | return retval; |
2087 | 2087 | ||
@@ -2167,9 +2167,9 @@ static int ptmx_open(struct inode * inode, struct file * filp) | |||
2167 | } | 2167 | } |
2168 | up(&allocated_ptys_lock); | 2168 | up(&allocated_ptys_lock); |
2169 | 2169 | ||
2170 | down(&tty_sem); | 2170 | mutex_lock(&tty_mutex); |
2171 | retval = init_dev(ptm_driver, index, &tty); | 2171 | retval = init_dev(ptm_driver, index, &tty); |
2172 | up(&tty_sem); | 2172 | mutex_unlock(&tty_mutex); |
2173 | 2173 | ||
2174 | if (retval) | 2174 | if (retval) |
2175 | goto out; | 2175 | goto out; |
@@ -2915,8 +2915,8 @@ static void initialize_tty_struct(struct tty_struct *tty) | |||
2915 | init_waitqueue_head(&tty->write_wait); | 2915 | init_waitqueue_head(&tty->write_wait); |
2916 | init_waitqueue_head(&tty->read_wait); | 2916 | init_waitqueue_head(&tty->read_wait); |
2917 | INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); | 2917 | INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); |
2918 | sema_init(&tty->atomic_read, 1); | 2918 | mutex_init(&tty->atomic_read_lock); |
2919 | sema_init(&tty->atomic_write, 1); | 2919 | mutex_init(&tty->atomic_write_lock); |
2920 | spin_lock_init(&tty->read_lock); | 2920 | spin_lock_init(&tty->read_lock); |
2921 | INIT_LIST_HEAD(&tty->tty_files); | 2921 | INIT_LIST_HEAD(&tty->tty_files); |
2922 | INIT_WORK(&tty->SAK_work, NULL, NULL); | 2922 | INIT_WORK(&tty->SAK_work, NULL, NULL); |