aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Kaehlcke <matthias.kaehlcke@gmail.com>2007-05-08 03:39:49 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:33 -0400
commitc831c338f0ad299fcd1592c6e4f30657480f39af (patch)
treee2562fbcffe80e9d78255a92aab7f7db1f761e9d
parent159dde93692ef549a0b2012c9f25feb4df638c9c (diff)
use mutex instead of semaphore in virtual console driver
The virtual console driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore. Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com> Cc: "Antonino A. Daplas" <adaplas@pol.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/char/vc_screen.c18
-rw-r--r--drivers/char/vt.c5
-rw-r--r--include/linux/vt_kern.h3
3 files changed, 15 insertions, 11 deletions
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index 61fbc9e52eeb..83aeedda200c 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -28,11 +28,13 @@
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/mutex.h>
31#include <linux/vt_kern.h> 32#include <linux/vt_kern.h>
32#include <linux/selection.h> 33#include <linux/selection.h>
33#include <linux/kbd_kern.h> 34#include <linux/kbd_kern.h>
34#include <linux/console.h> 35#include <linux/console.h>
35#include <linux/device.h> 36#include <linux/device.h>
37
36#include <asm/uaccess.h> 38#include <asm/uaccess.h>
37#include <asm/byteorder.h> 39#include <asm/byteorder.h>
38#include <asm/unaligned.h> 40#include <asm/unaligned.h>
@@ -69,11 +71,11 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
69{ 71{
70 int size; 72 int size;
71 73
72 down(&con_buf_sem); 74 mutex_lock(&con_buf_mtx);
73 size = vcs_size(file->f_path.dentry->d_inode); 75 size = vcs_size(file->f_path.dentry->d_inode);
74 switch (orig) { 76 switch (orig) {
75 default: 77 default:
76 up(&con_buf_sem); 78 mutex_unlock(&con_buf_mtx);
77 return -EINVAL; 79 return -EINVAL;
78 case 2: 80 case 2:
79 offset += size; 81 offset += size;
@@ -84,11 +86,11 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
84 break; 86 break;
85 } 87 }
86 if (offset < 0 || offset > size) { 88 if (offset < 0 || offset > size) {
87 up(&con_buf_sem); 89 mutex_unlock(&con_buf_mtx);
88 return -EINVAL; 90 return -EINVAL;
89 } 91 }
90 file->f_pos = offset; 92 file->f_pos = offset;
91 up(&con_buf_sem); 93 mutex_unlock(&con_buf_mtx);
92 return file->f_pos; 94 return file->f_pos;
93} 95}
94 96
@@ -105,7 +107,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
105 unsigned short *org = NULL; 107 unsigned short *org = NULL;
106 ssize_t ret; 108 ssize_t ret;
107 109
108 down(&con_buf_sem); 110 mutex_lock(&con_buf_mtx);
109 111
110 pos = *ppos; 112 pos = *ppos;
111 113
@@ -262,7 +264,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
262 ret = read; 264 ret = read;
263unlock_out: 265unlock_out:
264 release_console_sem(); 266 release_console_sem();
265 up(&con_buf_sem); 267 mutex_unlock(&con_buf_mtx);
266 return ret; 268 return ret;
267} 269}
268 270
@@ -279,7 +281,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
279 u16 *org0 = NULL, *org = NULL; 281 u16 *org0 = NULL, *org = NULL;
280 size_t ret; 282 size_t ret;
281 283
282 down(&con_buf_sem); 284 mutex_lock(&con_buf_mtx);
283 285
284 pos = *ppos; 286 pos = *ppos;
285 287
@@ -449,7 +451,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
449unlock_out: 451unlock_out:
450 release_console_sem(); 452 release_console_sem();
451 453
452 up(&con_buf_sem); 454 mutex_unlock(&con_buf_mtx);
453 455
454 return ret; 456 return ret;
455} 457}
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 0edbbc3fa9d8..bbd9fc412877 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -86,6 +86,7 @@
86#include <linux/mm.h> 86#include <linux/mm.h>
87#include <linux/console.h> 87#include <linux/console.h>
88#include <linux/init.h> 88#include <linux/init.h>
89#include <linux/mutex.h>
89#include <linux/vt_kern.h> 90#include <linux/vt_kern.h>
90#include <linux/selection.h> 91#include <linux/selection.h>
91#include <linux/tiocl.h> 92#include <linux/tiocl.h>
@@ -1952,7 +1953,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1952 * kernel memory allocation is available. 1953 * kernel memory allocation is available.
1953 */ 1954 */
1954char con_buf[CON_BUF_SIZE]; 1955char con_buf[CON_BUF_SIZE];
1955DECLARE_MUTEX(con_buf_sem); 1956DEFINE_MUTEX(con_buf_mtx);
1956 1957
1957/* is_double_width() is based on the wcwidth() implementation by 1958/* is_double_width() is based on the wcwidth() implementation by
1958 * Markus Kuhn -- 2003-05-20 (Unicode 4.0) 1959 * Markus Kuhn -- 2003-05-20 (Unicode 4.0)
@@ -2049,7 +2050,7 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2049 2050
2050 /* At this point 'buf' is guaranteed to be a kernel buffer 2051 /* At this point 'buf' is guaranteed to be a kernel buffer
2051 * and therefore no access to userspace (and therefore sleeping) 2052 * and therefore no access to userspace (and therefore sleeping)
2052 * will be needed. The con_buf_sem serializes all tty based 2053 * will be needed. The con_buf_mtx serializes all tty based
2053 * console rendering and vcs write/read operations. We hold 2054 * console rendering and vcs write/read operations. We hold
2054 * the console spinlock during the entire write. 2055 * the console spinlock during the entire write.
2055 */ 2056 */
diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h
index e0db669998f3..d961635d0e61 100644
--- a/include/linux/vt_kern.h
+++ b/include/linux/vt_kern.h
@@ -9,6 +9,7 @@
9#include <linux/vt.h> 9#include <linux/vt.h>
10#include <linux/kd.h> 10#include <linux/kd.h>
11#include <linux/tty.h> 11#include <linux/tty.h>
12#include <linux/mutex.h>
12#include <linux/console_struct.h> 13#include <linux/console_struct.h>
13#include <linux/mm.h> 14#include <linux/mm.h>
14 15
@@ -82,7 +83,7 @@ void reset_vc(struct vc_data *vc);
82 83
83#define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE) 84#define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE)
84extern char con_buf[CON_BUF_SIZE]; 85extern char con_buf[CON_BUF_SIZE];
85extern struct semaphore con_buf_sem; 86extern struct mutex con_buf_mtx;
86extern char vt_dont_switch; 87extern char vt_dont_switch;
87 88
88struct vt_spawn_console { 89struct vt_spawn_console {