aboutsummaryrefslogtreecommitdiffstats
path: root/sound/oss/soundcard.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2010-09-14 15:53:41 -0400
committerTakashi Iwai <tiwai@suse.de>2010-09-14 17:14:50 -0400
commit645ef9ef1fc0ff70456495b1e21d3420b7b08541 (patch)
treef5e5df85076f397690437f09cb56688b06a03dbf /sound/oss/soundcard.c
parent7b6c3a34e93aafc5dd9adc7dee87c7fa61d8bdbb (diff)
sound: autoconvert trivial BKL users to private mutex
The usage of the BKL in the OSS sound drivers is trivial, and each of them only locks against itself, so it can be turned into per-driver mutexes. This is the script that was used for the conversion: file=$1 name=$2 if grep -q lock_kernel ${file} ; then if grep -q 'include.*linux.mutex.h' ${file} ; then sed -i '/include.*<linux\/smp_lock.h>/d' ${file} else sed -i 's/include.*<linux\/smp_lock.h>.*$/include <linux\/mutex.h>/g' ${file} fi sed -i ${file} \ -e "/^#include.*linux.mutex.h/,$ { 1,/^\(static\|int\|long\)/ { /^\(static\|int\|long\)/istatic DEFINE_MUTEX(${name}_mutex); } }" \ -e "s/\(un\)*lock_kernel\>[ ]*()/mutex_\1lock(\&${name}_mutex)/g" \ -e '/[ ]*cycle_kernel_lock();/d' else sed -i -e '/include.*\<smp_lock.h\>/d' ${file} \ -e '/cycle_kernel_lock()/d' fi Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/oss/soundcard.c')
-rw-r--r--sound/oss/soundcard.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
index 92aa762ffb7e..938ed94f904f 100644
--- a/sound/oss/soundcard.c
+++ b/sound/oss/soundcard.c
@@ -40,7 +40,7 @@
40#include <linux/major.h> 40#include <linux/major.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/proc_fs.h> 42#include <linux/proc_fs.h>
43#include <linux/smp_lock.h> 43#include <linux/mutex.h>
44#include <linux/module.h> 44#include <linux/module.h>
45#include <linux/mm.h> 45#include <linux/mm.h>
46#include <linux/device.h> 46#include <linux/device.h>
@@ -56,6 +56,7 @@
56 * Table for permanently allocated memory (used when unloading the module) 56 * Table for permanently allocated memory (used when unloading the module)
57 */ 57 */
58void * sound_mem_blocks[MAX_MEM_BLOCKS]; 58void * sound_mem_blocks[MAX_MEM_BLOCKS];
59static DEFINE_MUTEX(soundcard_mutex);
59int sound_nblocks = 0; 60int sound_nblocks = 0;
60 61
61/* Persistent DMA buffers */ 62/* Persistent DMA buffers */
@@ -151,7 +152,7 @@ static ssize_t sound_read(struct file *file, char __user *buf, size_t count, lof
151 * big one anyway, we might as well bandage here.. 152 * big one anyway, we might as well bandage here..
152 */ 153 */
153 154
154 lock_kernel(); 155 mutex_lock(&soundcard_mutex);
155 156
156 DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count)); 157 DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count));
157 switch (dev & 0x0f) { 158 switch (dev & 0x0f) {
@@ -169,7 +170,7 @@ static ssize_t sound_read(struct file *file, char __user *buf, size_t count, lof
169 case SND_DEV_MIDIN: 170 case SND_DEV_MIDIN:
170 ret = MIDIbuf_read(dev, file, buf, count); 171 ret = MIDIbuf_read(dev, file, buf, count);
171 } 172 }
172 unlock_kernel(); 173 mutex_unlock(&soundcard_mutex);
173 return ret; 174 return ret;
174} 175}
175 176
@@ -178,7 +179,7 @@ static ssize_t sound_write(struct file *file, const char __user *buf, size_t cou
178 int dev = iminor(file->f_path.dentry->d_inode); 179 int dev = iminor(file->f_path.dentry->d_inode);
179 int ret = -EINVAL; 180 int ret = -EINVAL;
180 181
181 lock_kernel(); 182 mutex_lock(&soundcard_mutex);
182 DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count)); 183 DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count));
183 switch (dev & 0x0f) { 184 switch (dev & 0x0f) {
184 case SND_DEV_SEQ: 185 case SND_DEV_SEQ:
@@ -196,7 +197,7 @@ static ssize_t sound_write(struct file *file, const char __user *buf, size_t cou
196 ret = MIDIbuf_write(dev, file, buf, count); 197 ret = MIDIbuf_write(dev, file, buf, count);
197 break; 198 break;
198 } 199 }
199 unlock_kernel(); 200 mutex_unlock(&soundcard_mutex);
200 return ret; 201 return ret;
201} 202}
202 203
@@ -210,7 +211,7 @@ static int sound_open(struct inode *inode, struct file *file)
210 printk(KERN_ERR "Invalid minor device %d\n", dev); 211 printk(KERN_ERR "Invalid minor device %d\n", dev);
211 return -ENXIO; 212 return -ENXIO;
212 } 213 }
213 lock_kernel(); 214 mutex_lock(&soundcard_mutex);
214 switch (dev & 0x0f) { 215 switch (dev & 0x0f) {
215 case SND_DEV_CTL: 216 case SND_DEV_CTL:
216 dev >>= 4; 217 dev >>= 4;
@@ -247,7 +248,7 @@ static int sound_open(struct inode *inode, struct file *file)
247 retval = -ENXIO; 248 retval = -ENXIO;
248 } 249 }
249 250
250 unlock_kernel(); 251 mutex_unlock(&soundcard_mutex);
251 return 0; 252 return 0;
252} 253}
253 254
@@ -255,7 +256,7 @@ static int sound_release(struct inode *inode, struct file *file)
255{ 256{
256 int dev = iminor(inode); 257 int dev = iminor(inode);
257 258
258 lock_kernel(); 259 mutex_lock(&soundcard_mutex);
259 DEB(printk("sound_release(dev=%d)\n", dev)); 260 DEB(printk("sound_release(dev=%d)\n", dev));
260 switch (dev & 0x0f) { 261 switch (dev & 0x0f) {
261 case SND_DEV_CTL: 262 case SND_DEV_CTL:
@@ -280,7 +281,7 @@ static int sound_release(struct inode *inode, struct file *file)
280 default: 281 default:
281 printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev); 282 printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev);
282 } 283 }
283 unlock_kernel(); 284 mutex_unlock(&soundcard_mutex);
284 285
285 return 0; 286 return 0;
286} 287}
@@ -354,7 +355,7 @@ static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
354 if (cmd == OSS_GETVERSION) 355 if (cmd == OSS_GETVERSION)
355 return __put_user(SOUND_VERSION, (int __user *)p); 356 return __put_user(SOUND_VERSION, (int __user *)p);
356 357
357 lock_kernel(); 358 mutex_lock(&soundcard_mutex);
358 if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */ 359 if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */
359 (dev & 0x0f) != SND_DEV_CTL) { 360 (dev & 0x0f) != SND_DEV_CTL) {
360 dtype = dev & 0x0f; 361 dtype = dev & 0x0f;
@@ -369,7 +370,7 @@ static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
369 ret = sound_mixer_ioctl(dev >> 4, cmd, p); 370 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
370 break; 371 break;
371 } 372 }
372 unlock_kernel(); 373 mutex_unlock(&soundcard_mutex);
373 return ret; 374 return ret;
374 } 375 }
375 376
@@ -399,7 +400,7 @@ static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
399 break; 400 break;
400 401
401 } 402 }
402 unlock_kernel(); 403 mutex_unlock(&soundcard_mutex);
403 return ret; 404 return ret;
404} 405}
405 406
@@ -439,35 +440,35 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma)
439 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n"); 440 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
440 return -EINVAL; 441 return -EINVAL;
441 } 442 }
442 lock_kernel(); 443 mutex_lock(&soundcard_mutex);
443 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */ 444 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
444 dmap = audio_devs[dev]->dmap_out; 445 dmap = audio_devs[dev]->dmap_out;
445 else if (vma->vm_flags & VM_READ) 446 else if (vma->vm_flags & VM_READ)
446 dmap = audio_devs[dev]->dmap_in; 447 dmap = audio_devs[dev]->dmap_in;
447 else { 448 else {
448 printk(KERN_ERR "Sound: Undefined mmap() access\n"); 449 printk(KERN_ERR "Sound: Undefined mmap() access\n");
449 unlock_kernel(); 450 mutex_unlock(&soundcard_mutex);
450 return -EINVAL; 451 return -EINVAL;
451 } 452 }
452 453
453 if (dmap == NULL) { 454 if (dmap == NULL) {
454 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n"); 455 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
455 unlock_kernel(); 456 mutex_unlock(&soundcard_mutex);
456 return -EIO; 457 return -EIO;
457 } 458 }
458 if (dmap->raw_buf == NULL) { 459 if (dmap->raw_buf == NULL) {
459 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n"); 460 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
460 unlock_kernel(); 461 mutex_unlock(&soundcard_mutex);
461 return -EIO; 462 return -EIO;
462 } 463 }
463 if (dmap->mapping_flags) { 464 if (dmap->mapping_flags) {
464 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n"); 465 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
465 unlock_kernel(); 466 mutex_unlock(&soundcard_mutex);
466 return -EIO; 467 return -EIO;
467 } 468 }
468 if (vma->vm_pgoff != 0) { 469 if (vma->vm_pgoff != 0) {
469 printk(KERN_ERR "Sound: mmap() offset must be 0.\n"); 470 printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
470 unlock_kernel(); 471 mutex_unlock(&soundcard_mutex);
471 return -EINVAL; 472 return -EINVAL;
472 } 473 }
473 size = vma->vm_end - vma->vm_start; 474 size = vma->vm_end - vma->vm_start;
@@ -478,7 +479,7 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma)
478 if (remap_pfn_range(vma, vma->vm_start, 479 if (remap_pfn_range(vma, vma->vm_start,
479 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT, 480 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
480 vma->vm_end - vma->vm_start, vma->vm_page_prot)) { 481 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
481 unlock_kernel(); 482 mutex_unlock(&soundcard_mutex);
482 return -EAGAIN; 483 return -EAGAIN;
483 } 484 }
484 485
@@ -490,7 +491,7 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma)
490 memset(dmap->raw_buf, 491 memset(dmap->raw_buf,
491 dmap->neutral_byte, 492 dmap->neutral_byte,
492 dmap->bytes_in_use); 493 dmap->bytes_in_use);
493 unlock_kernel(); 494 mutex_unlock(&soundcard_mutex);
494 return 0; 495 return 0;
495} 496}
496 497