aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMatthias Kaehlcke <matthias.kaehlcke@gmail.com>2007-05-08 03:32:08 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:15 -0400
commit0e82d5b61841f2b9e2d31a4299ce09752c5d3288 (patch)
treeb8d6009112eb44425fca70779f4bc2337e9df6ca /drivers
parent6acc369a43ada9b829b3e1e4daef5c8a52a2d39a (diff)
use mutex instead of semaphore for misc char devices
The misc character device driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore. Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/misc.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 7e975f606924..4e6fb9651a16 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -41,6 +41,7 @@
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/major.h> 42#include <linux/major.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/mutex.h>
44#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
45#include <linux/seq_file.h> 46#include <linux/seq_file.h>
46#include <linux/stat.h> 47#include <linux/stat.h>
@@ -53,7 +54,7 @@
53 * Head entry for the doubly linked miscdevice list 54 * Head entry for the doubly linked miscdevice list
54 */ 55 */
55static LIST_HEAD(misc_list); 56static LIST_HEAD(misc_list);
56static DECLARE_MUTEX(misc_sem); 57static DEFINE_MUTEX(misc_mtx);
57 58
58/* 59/*
59 * Assigned numbers, used for dynamic minors 60 * Assigned numbers, used for dynamic minors
@@ -69,7 +70,7 @@ static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
69 struct miscdevice *p; 70 struct miscdevice *p;
70 loff_t off = 0; 71 loff_t off = 0;
71 72
72 down(&misc_sem); 73 mutex_lock(&misc_mtx);
73 list_for_each_entry(p, &misc_list, list) { 74 list_for_each_entry(p, &misc_list, list) {
74 if (*pos == off++) 75 if (*pos == off++)
75 return p; 76 return p;
@@ -89,7 +90,7 @@ static void *misc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
89 90
90static void misc_seq_stop(struct seq_file *seq, void *v) 91static void misc_seq_stop(struct seq_file *seq, void *v)
91{ 92{
92 up(&misc_sem); 93 mutex_unlock(&misc_mtx);
93} 94}
94 95
95static int misc_seq_show(struct seq_file *seq, void *v) 96static int misc_seq_show(struct seq_file *seq, void *v)
@@ -129,7 +130,7 @@ static int misc_open(struct inode * inode, struct file * file)
129 int err = -ENODEV; 130 int err = -ENODEV;
130 const struct file_operations *old_fops, *new_fops = NULL; 131 const struct file_operations *old_fops, *new_fops = NULL;
131 132
132 down(&misc_sem); 133 mutex_lock(&misc_mtx);
133 134
134 list_for_each_entry(c, &misc_list, list) { 135 list_for_each_entry(c, &misc_list, list) {
135 if (c->minor == minor) { 136 if (c->minor == minor) {
@@ -139,9 +140,9 @@ static int misc_open(struct inode * inode, struct file * file)
139 } 140 }
140 141
141 if (!new_fops) { 142 if (!new_fops) {
142 up(&misc_sem); 143 mutex_unlock(&misc_mtx);
143 request_module("char-major-%d-%d", MISC_MAJOR, minor); 144 request_module("char-major-%d-%d", MISC_MAJOR, minor);
144 down(&misc_sem); 145 mutex_lock(&misc_mtx);
145 146
146 list_for_each_entry(c, &misc_list, list) { 147 list_for_each_entry(c, &misc_list, list) {
147 if (c->minor == minor) { 148 if (c->minor == minor) {
@@ -165,7 +166,7 @@ static int misc_open(struct inode * inode, struct file * file)
165 } 166 }
166 fops_put(old_fops); 167 fops_put(old_fops);
167fail: 168fail:
168 up(&misc_sem); 169 mutex_unlock(&misc_mtx);
169 return err; 170 return err;
170} 171}
171 172
@@ -201,10 +202,10 @@ int misc_register(struct miscdevice * misc)
201 202
202 INIT_LIST_HEAD(&misc->list); 203 INIT_LIST_HEAD(&misc->list);
203 204
204 down(&misc_sem); 205 mutex_lock(&misc_mtx);
205 list_for_each_entry(c, &misc_list, list) { 206 list_for_each_entry(c, &misc_list, list) {
206 if (c->minor == misc->minor) { 207 if (c->minor == misc->minor) {
207 up(&misc_sem); 208 mutex_unlock(&misc_mtx);
208 return -EBUSY; 209 return -EBUSY;
209 } 210 }
210 } 211 }
@@ -215,7 +216,7 @@ int misc_register(struct miscdevice * misc)
215 if ( (misc_minors[i>>3] & (1 << (i&7))) == 0) 216 if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
216 break; 217 break;
217 if (i<0) { 218 if (i<0) {
218 up(&misc_sem); 219 mutex_unlock(&misc_mtx);
219 return -EBUSY; 220 return -EBUSY;
220 } 221 }
221 misc->minor = i; 222 misc->minor = i;
@@ -238,7 +239,7 @@ int misc_register(struct miscdevice * misc)
238 */ 239 */
239 list_add(&misc->list, &misc_list); 240 list_add(&misc->list, &misc_list);
240 out: 241 out:
241 up(&misc_sem); 242 mutex_unlock(&misc_mtx);
242 return err; 243 return err;
243} 244}
244 245
@@ -259,13 +260,13 @@ int misc_deregister(struct miscdevice * misc)
259 if (list_empty(&misc->list)) 260 if (list_empty(&misc->list))
260 return -EINVAL; 261 return -EINVAL;
261 262
262 down(&misc_sem); 263 mutex_lock(&misc_mtx);
263 list_del(&misc->list); 264 list_del(&misc->list);
264 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 265 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
265 if (i < DYNAMIC_MINORS && i>0) { 266 if (i < DYNAMIC_MINORS && i>0) {
266 misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); 267 misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
267 } 268 }
268 up(&misc_sem); 269 mutex_unlock(&misc_mtx);
269 return 0; 270 return 0;
270} 271}
271 272