Commit 70522e121a521aa09bd0f4e62e1aa68708b798e1

Authored by Ingo Molnar
Committed by Linus Torvalds
1 parent d4f9af9dac

[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: Ingo Molnar <mingo@elte.hu>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 6 changed files with 45 additions and 45 deletions Side-by-side Diff

drivers/char/n_tty.c
... ... @@ -132,7 +132,7 @@
132 132 * We test the TTY_THROTTLED bit first so that it always
133 133 * indicates the current state. The decision about whether
134 134 * it is worth allowing more input has been taken by the caller.
135   - * Can sleep, may be called under the atomic_read semaphore but
  135 + * Can sleep, may be called under the atomic_read_lock mutex but
136 136 * this is not guaranteed.
137 137 */
138 138  
... ... @@ -1132,7 +1132,7 @@
1132 1132 * buffer, and once to drain the space from the (physical) beginning of
1133 1133 * the buffer to head pointer.
1134 1134 *
1135   - * Called under the tty->atomic_read sem and with TTY_DONT_FLIP set
  1135 + * Called under the tty->atomic_read_lock sem and with TTY_DONT_FLIP set
1136 1136 *
1137 1137 */
1138 1138  
1139 1139  
... ... @@ -1262,11 +1262,11 @@
1262 1262 * Internal serialization of reads.
1263 1263 */
1264 1264 if (file->f_flags & O_NONBLOCK) {
1265   - if (down_trylock(&tty->atomic_read))
  1265 + if (!mutex_trylock(&tty->atomic_read_lock))
1266 1266 return -EAGAIN;
1267 1267 }
1268 1268 else {
1269   - if (down_interruptible(&tty->atomic_read))
  1269 + if (mutex_lock_interruptible(&tty->atomic_read_lock))
1270 1270 return -ERESTARTSYS;
1271 1271 }
1272 1272  
... ... @@ -1393,7 +1393,7 @@
1393 1393 timeout = time;
1394 1394 }
1395 1395 clear_bit(TTY_DONT_FLIP, &tty->flags);
1396   - up(&tty->atomic_read);
  1396 + mutex_unlock(&tty->atomic_read_lock);
1397 1397 remove_wait_queue(&tty->read_wait, &wait);
1398 1398  
1399 1399 if (!waitqueue_active(&tty->read_wait))
drivers/char/tty_io.c
... ... @@ -130,7 +130,7 @@
130 130  
131 131 /* Semaphore to protect creating and releasing a tty. This is shared with
132 132 vt.c for deeply disgusting hack reasons */
133   -DECLARE_MUTEX(tty_sem);
  133 +DEFINE_MUTEX(tty_mutex);
134 134  
135 135 #ifdef CONFIG_UNIX98_PTYS
136 136 extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
137 137  
... ... @@ -1188,11 +1188,11 @@
1188 1188  
1189 1189 lock_kernel();
1190 1190  
1191   - down(&tty_sem);
  1191 + mutex_lock(&tty_mutex);
1192 1192 tty = current->signal->tty;
1193 1193 if (tty) {
1194 1194 tty_pgrp = tty->pgrp;
1195   - up(&tty_sem);
  1195 + mutex_unlock(&tty_mutex);
1196 1196 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1197 1197 tty_vhangup(tty);
1198 1198 } else {
... ... @@ -1200,7 +1200,7 @@
1200 1200 kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
1201 1201 kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
1202 1202 }
1203   - up(&tty_sem);
  1203 + mutex_unlock(&tty_mutex);
1204 1204 unlock_kernel();
1205 1205 return;
1206 1206 }
... ... @@ -1211,7 +1211,7 @@
1211 1211 }
1212 1212  
1213 1213 /* Must lock changes to tty_old_pgrp */
1214   - down(&tty_sem);
  1214 + mutex_lock(&tty_mutex);
1215 1215 current->signal->tty_old_pgrp = 0;
1216 1216 tty->session = 0;
1217 1217 tty->pgrp = -1;
... ... @@ -1222,7 +1222,7 @@
1222 1222 p->signal->tty = NULL;
1223 1223 } while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
1224 1224 read_unlock(&tasklist_lock);
1225   - up(&tty_sem);
  1225 + mutex_unlock(&tty_mutex);
1226 1226 unlock_kernel();
1227 1227 }
1228 1228  
... ... @@ -1306,7 +1306,7 @@
1306 1306 ssize_t ret = 0, written = 0;
1307 1307 unsigned int chunk;
1308 1308  
1309   - if (down_interruptible(&tty->atomic_write)) {
  1309 + if (mutex_lock_interruptible(&tty->atomic_write_lock)) {
1310 1310 return -ERESTARTSYS;
1311 1311 }
1312 1312  
... ... @@ -1329,7 +1329,7 @@
1329 1329 if (count < chunk)
1330 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 1333 if (tty->write_cnt < chunk) {
1334 1334 unsigned char *buf;
1335 1335  
... ... @@ -1338,7 +1338,7 @@
1338 1338  
1339 1339 buf = kmalloc(chunk, GFP_KERNEL);
1340 1340 if (!buf) {
1341   - up(&tty->atomic_write);
  1341 + mutex_unlock(&tty->atomic_write_lock);
1342 1342 return -ENOMEM;
1343 1343 }
1344 1344 kfree(tty->write_buf);
... ... @@ -1374,7 +1374,7 @@
1374 1374 inode->i_mtime = current_fs_time(inode->i_sb);
1375 1375 ret = written;
1376 1376 }
1377   - up(&tty->atomic_write);
  1377 + mutex_unlock(&tty->atomic_write_lock);
1378 1378 return ret;
1379 1379 }
1380 1380  
... ... @@ -1442,8 +1442,8 @@
1442 1442  
1443 1443 /*
1444 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
1446   - * really quite straightforward. The semaphore locking can probably be
  1445 + * failed open. The new code protects the open with a mutex, so it's
  1446 + * really quite straightforward. The mutex locking can probably be
1447 1447 * relaxed for the (most common) case of reopening a tty.
1448 1448 */
1449 1449 static int init_dev(struct tty_driver *driver, int idx,
... ... @@ -1640,7 +1640,7 @@
1640 1640 success:
1641 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 1644 end_init:
1645 1645 return retval;
1646 1646  
... ... @@ -1837,7 +1837,7 @@
1837 1837 /* Guard against races with tty->count changes elsewhere and
1838 1838 opens on /dev/tty */
1839 1839  
1840   - down(&tty_sem);
  1840 + mutex_lock(&tty_mutex);
1841 1841 tty_closing = tty->count <= 1;
1842 1842 o_tty_closing = o_tty &&
1843 1843 (o_tty->count <= (pty_master ? 1 : 0));
... ... @@ -1868,7 +1868,7 @@
1868 1868  
1869 1869 printk(KERN_WARNING "release_dev: %s: read/write wait queue "
1870 1870 "active!\n", tty_name(tty, buf));
1871   - up(&tty_sem);
  1871 + mutex_unlock(&tty_mutex);
1872 1872 schedule();
1873 1873 }
1874 1874  
... ... @@ -1934,7 +1934,7 @@
1934 1934 read_unlock(&tasklist_lock);
1935 1935 }
1936 1936  
1937   - up(&tty_sem);
  1937 + mutex_unlock(&tty_mutex);
1938 1938  
1939 1939 /* check whether both sides are closing ... */
1940 1940 if (!tty_closing || (o_tty && !o_tty_closing))
1941 1941  
... ... @@ -2040,11 +2040,11 @@
2040 2040 index = -1;
2041 2041 retval = 0;
2042 2042  
2043   - down(&tty_sem);
  2043 + mutex_lock(&tty_mutex);
2044 2044  
2045 2045 if (device == MKDEV(TTYAUX_MAJOR,0)) {
2046 2046 if (!current->signal->tty) {
2047   - up(&tty_sem);
  2047 + mutex_unlock(&tty_mutex);
2048 2048 return -ENXIO;
2049 2049 }
2050 2050 driver = current->signal->tty->driver;
2051 2051  
2052 2052  
... ... @@ -2070,18 +2070,18 @@
2070 2070 noctty = 1;
2071 2071 goto got_driver;
2072 2072 }
2073   - up(&tty_sem);
  2073 + mutex_unlock(&tty_mutex);
2074 2074 return -ENODEV;
2075 2075 }
2076 2076  
2077 2077 driver = get_tty_driver(device, &index);
2078 2078 if (!driver) {
2079   - up(&tty_sem);
  2079 + mutex_unlock(&tty_mutex);
2080 2080 return -ENODEV;
2081 2081 }
2082 2082 got_driver:
2083 2083 retval = init_dev(driver, index, &tty);
2084   - up(&tty_sem);
  2084 + mutex_unlock(&tty_mutex);
2085 2085 if (retval)
2086 2086 return retval;
2087 2087  
2088 2088  
... ... @@ -2167,9 +2167,9 @@
2167 2167 }
2168 2168 up(&allocated_ptys_lock);
2169 2169  
2170   - down(&tty_sem);
  2170 + mutex_lock(&tty_mutex);
2171 2171 retval = init_dev(ptm_driver, index, &tty);
2172   - up(&tty_sem);
  2172 + mutex_unlock(&tty_mutex);
2173 2173  
2174 2174 if (retval)
2175 2175 goto out;
... ... @@ -2915,8 +2915,8 @@
2915 2915 init_waitqueue_head(&tty->write_wait);
2916 2916 init_waitqueue_head(&tty->read_wait);
2917 2917 INIT_WORK(&tty->hangup_work, do_tty_hangup, tty);
2918   - sema_init(&tty->atomic_read, 1);
2919   - sema_init(&tty->atomic_write, 1);
  2918 + mutex_init(&tty->atomic_read_lock);
  2919 + mutex_init(&tty->atomic_write_lock);
2920 2920 spin_lock_init(&tty->read_lock);
2921 2921 INIT_LIST_HEAD(&tty->tty_files);
2922 2922 INIT_WORK(&tty->SAK_work, NULL, NULL);
... ... @@ -2489,7 +2489,7 @@
2489 2489 }
2490 2490  
2491 2491 /*
2492   - * We take tty_sem in here to prevent another thread from coming in via init_dev
  2492 + * We take tty_mutex in here to prevent another thread from coming in via init_dev
2493 2493 * and taking a ref against the tty while we're in the process of forgetting
2494 2494 * about it and cleaning things up.
2495 2495 *
... ... @@ -2497,7 +2497,7 @@
2497 2497 */
2498 2498 static void con_close(struct tty_struct *tty, struct file *filp)
2499 2499 {
2500   - down(&tty_sem);
  2500 + mutex_lock(&tty_mutex);
2501 2501 acquire_console_sem();
2502 2502 if (tty && tty->count == 1) {
2503 2503 struct vc_data *vc = tty->driver_data;
2504 2504  
2505 2505  
... ... @@ -2507,15 +2507,15 @@
2507 2507 tty->driver_data = NULL;
2508 2508 release_console_sem();
2509 2509 vcs_remove_devfs(tty);
2510   - up(&tty_sem);
  2510 + mutex_unlock(&tty_mutex);
2511 2511 /*
2512   - * tty_sem is released, but we still hold BKL, so there is
  2512 + * tty_mutex is released, but we still hold BKL, so there is
2513 2513 * still exclusion against init_dev()
2514 2514 */
2515 2515 return;
2516 2516 }
2517 2517 release_console_sem();
2518   - up(&tty_sem);
  2518 + mutex_unlock(&tty_mutex);
2519 2519 }
2520 2520  
2521 2521 static void vc_init(struct vc_data *vc, unsigned int rows,
2522 2522  
... ... @@ -2869,9 +2869,9 @@
2869 2869 }
2870 2870  
2871 2871 /*
2872   - * We defer the timer blanking to work queue so it can take the console semaphore
  2872 + * We defer the timer blanking to work queue so it can take the console mutex
2873 2873 * (console operations can still happen at irq time, but only from printk which
2874   - * has the console semaphore. Not perfect yet, but better than no locking
  2874 + * has the console mutex. Not perfect yet, but better than no locking
2875 2875 */
2876 2876 static void blank_screen_t(unsigned long dummy)
2877 2877 {
... ... @@ -24,6 +24,7 @@
24 24 #include <linux/tty_driver.h>
25 25 #include <linux/tty_ldisc.h>
26 26 #include <linux/screen_info.h>
  27 +#include <linux/mutex.h>
27 28  
28 29 #include <asm/system.h>
29 30  
... ... @@ -231,8 +232,8 @@
231 232 int canon_data;
232 233 unsigned long canon_head;
233 234 unsigned int canon_column;
234   - struct semaphore atomic_read;
235   - struct semaphore atomic_write;
  235 + struct mutex atomic_read_lock;
  236 + struct mutex atomic_write_lock;
236 237 unsigned char *write_buf;
237 238 int write_cnt;
238 239 spinlock_t read_lock;
... ... @@ -319,8 +320,7 @@
319 320 extern void tty_wakeup(struct tty_struct *tty);
320 321 extern void tty_ldisc_flush(struct tty_struct *tty);
321 322  
322   -struct semaphore;
323   -extern struct semaphore tty_sem;
  323 +extern struct mutex tty_mutex;
324 324  
325 325 /* n_tty.c */
326 326 extern struct tty_ldisc tty_ldisc_N_TTY;
... ... @@ -345,9 +345,9 @@
345 345 exit_mm(current);
346 346  
347 347 set_special_pids(1, 1);
348   - down(&tty_sem);
  348 + mutex_lock(&tty_mutex);
349 349 current->signal->tty = NULL;
350   - up(&tty_sem);
  350 + mutex_unlock(&tty_mutex);
351 351  
352 352 /* Block and flush all signals */
353 353 sigfillset(&blocked);
... ... @@ -1227,7 +1227,7 @@
1227 1227 struct pid *pid;
1228 1228 int err = -EPERM;
1229 1229  
1230   - down(&tty_sem);
  1230 + mutex_lock(&tty_mutex);
1231 1231 write_lock_irq(&tasklist_lock);
1232 1232  
1233 1233 pid = find_pid(PIDTYPE_PGID, group_leader->pid);
... ... @@ -1241,7 +1241,7 @@
1241 1241 err = process_group(group_leader);
1242 1242 out:
1243 1243 write_unlock_irq(&tasklist_lock);
1244   - up(&tty_sem);
  1244 + mutex_unlock(&tty_mutex);
1245 1245 return err;
1246 1246 }
1247 1247