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>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Ingo Molnar 2006-03-23 03:00:39 -08:00 коммит произвёл Linus Torvalds
Родитель 82d4dc5adb
Коммит 910f5d202c
27 изменённых файлов: 449 добавлений и 410 удалений

Просмотреть файл

@ -56,7 +56,8 @@
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
#include <asm/semaphore.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include "sound_config.h"
@ -79,7 +80,7 @@ static int aci_micpreamp=3; /* microphone preamp-level that can't be *
* checked with ACI versions prior to 0xb0 */
static int mixer_device;
static struct semaphore aci_sem;
static struct mutex aci_mutex;
#ifdef MODULE
static int reset;
@ -212,7 +213,7 @@ int aci_rw_cmd(int write1, int write2, int write3)
int write[] = {write1, write2, write3};
int read = -EINTR, i;
if (down_interruptible(&aci_sem))
if (mutex_lock_interruptible(&aci_mutex))
goto out;
for (i=0; i<3; i++) {
@ -227,7 +228,7 @@ int aci_rw_cmd(int write1, int write2, int write3)
}
read = aci_rawread();
out_up: up(&aci_sem);
out_up: mutex_unlock(&aci_mutex);
out: return read;
}
@ -603,7 +604,7 @@ static int __init attach_aci(void)
char *boardname;
int i, rc = -EBUSY;
init_MUTEX(&aci_sem);
mutex_init(&aci_mutex);
outb(0xE3, 0xf8f); /* Write MAD16 password */
aci_port = (inb(0xf90) & 0x10) ?

Просмотреть файл

@ -38,6 +38,7 @@
#include <linux/ac97_codec.h>
#include <linux/sound.h>
#include <linux/interrupt.h>
#include <linux/mutex.h>
#include <asm/delay.h>
#include <asm/io.h>
@ -238,7 +239,7 @@ static ad1889_dev_t *ad1889_alloc_dev(struct pci_dev *pci)
for (i = 0; i < AD_MAX_STATES; i++) {
dev->state[i].card = dev;
init_MUTEX(&dev->state[i].sem);
mutex_init(&dev->state[i].mutex);
init_waitqueue_head(&dev->state[i].dmabuf.wait);
}
@ -461,7 +462,7 @@ static ssize_t ad1889_write(struct file *file, const char __user *buffer, size_t
ssize_t ret = 0;
DECLARE_WAITQUEUE(wait, current);
down(&state->sem);
mutex_lock(&state->mutex);
#if 0
if (dmabuf->mapped) {
ret = -ENXIO;
@ -546,7 +547,7 @@ static ssize_t ad1889_write(struct file *file, const char __user *buffer, size_t
err2:
remove_wait_queue(&state->dmabuf.wait, &wait);
err1:
up(&state->sem);
mutex_unlock(&state->mutex);
return ret;
}

Просмотреть файл

@ -100,7 +100,7 @@ typedef struct ad1889_state {
unsigned int subdivision;
} dmabuf;
struct semaphore sem;
struct mutex mutex;
} ad1889_state_t;
typedef struct ad1889_dev {

Просмотреть файл

@ -64,6 +64,8 @@
#include <linux/smp_lock.h>
#include <linux/ac97_codec.h>
#include <linux/interrupt.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#ifndef PCI_DEVICE_ID_ALI_5455
@ -234,7 +236,7 @@ struct ali_state {
struct ali_card *card; /* Card info */
/* single open lock mechanism, only used for recording */
struct semaphore open_sem;
struct mutex open_mutex;
wait_queue_head_t open_wait;
/* file mode */
@ -2807,7 +2809,7 @@ found_virt:
state->card = card;
state->magic = ALI5455_STATE_MAGIC;
init_waitqueue_head(&dmabuf->wait);
init_MUTEX(&state->open_sem);
mutex_init(&state->open_mutex);
file->private_data = state;
dmabuf->trigger = 0;
/* allocate hardware channels */
@ -3359,7 +3361,7 @@ static void __devinit ali_configure_clocking(void)
state->card = card;
state->magic = ALI5455_STATE_MAGIC;
init_waitqueue_head(&dmabuf->wait);
init_MUTEX(&state->open_sem);
mutex_init(&state->open_mutex);
dmabuf->fmt = ALI5455_FMT_STEREO | ALI5455_FMT_16BIT;
dmabuf->trigger = PCM_ENABLE_OUTPUT;
ali_set_dac_rate(state, 48000);

Просмотреть файл

@ -68,6 +68,8 @@
#include <linux/smp_lock.h>
#include <linux/ac97_codec.h>
#include <linux/interrupt.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/mach-au1x00/au1000.h>
@ -120,8 +122,8 @@ struct au1000_state {
int no_vra; // do not use VRA
spinlock_t lock;
struct semaphore open_sem;
struct semaphore sem;
struct mutex open_mutex;
struct mutex sem;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1106,7 +1108,7 @@ static ssize_t au1000_read(struct file *file, char *buffer,
count *= db->cnt_factor;
down(&s->sem);
mutex_lock(&s->sem);
add_wait_queue(&db->wait, &wait);
while (count > 0) {
@ -1125,14 +1127,14 @@ static ssize_t au1000_read(struct file *file, char *buffer,
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->sem);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out2;
}
down(&s->sem);
mutex_lock(&s->sem);
}
} while (avail <= 0);
@ -1159,7 +1161,7 @@ static ssize_t au1000_read(struct file *file, char *buffer,
} // while (count > 0)
out:
up(&s->sem);
mutex_unlock(&s->sem);
out2:
remove_wait_queue(&db->wait, &wait);
set_current_state(TASK_RUNNING);
@ -1187,7 +1189,7 @@ static ssize_t au1000_write(struct file *file, const char *buffer,
count *= db->cnt_factor;
down(&s->sem);
mutex_lock(&s->sem);
add_wait_queue(&db->wait, &wait);
while (count > 0) {
@ -1204,14 +1206,14 @@ static ssize_t au1000_write(struct file *file, const char *buffer,
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->sem);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out2;
}
down(&s->sem);
mutex_lock(&s->sem);
}
} while (avail <= 0);
@ -1240,7 +1242,7 @@ static ssize_t au1000_write(struct file *file, const char *buffer,
} // while (count > 0)
out:
up(&s->sem);
mutex_unlock(&s->sem);
out2:
remove_wait_queue(&db->wait, &wait);
set_current_state(TASK_RUNNING);
@ -1298,7 +1300,7 @@ static int au1000_mmap(struct file *file, struct vm_area_struct *vma)
dbg("%s", __FUNCTION__);
lock_kernel();
down(&s->sem);
mutex_lock(&s->sem);
if (vma->vm_flags & VM_WRITE)
db = &s->dma_dac;
else if (vma->vm_flags & VM_READ)
@ -1324,7 +1326,7 @@ static int au1000_mmap(struct file *file, struct vm_area_struct *vma)
vma->vm_flags &= ~VM_IO;
db->mapped = 1;
out:
up(&s->sem);
mutex_unlock(&s->sem);
unlock_kernel();
return ret;
}
@ -1829,21 +1831,21 @@ static int au1000_open(struct inode *inode, struct file *file)
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
stop_dac(s);
@ -1879,8 +1881,8 @@ static int au1000_open(struct inode *inode, struct file *file)
}
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
init_MUTEX(&s->sem);
mutex_unlock(&s->open_mutex);
mutex_init(&s->sem);
return nonseekable_open(inode, file);
}
@ -1896,7 +1898,7 @@ static int au1000_release(struct inode *inode, struct file *file)
lock_kernel();
}
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
dealloc_dmabuf(s, &s->dma_dac);
@ -1906,7 +1908,7 @@ static int au1000_release(struct inode *inode, struct file *file)
dealloc_dmabuf(s, &s->dma_adc);
}
s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -1996,7 +1998,7 @@ static int __devinit au1000_probe(void)
init_waitqueue_head(&s->dma_adc.wait);
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->codec.private_data = s;
s->codec.id = 0;

Просмотреть файл

@ -52,6 +52,8 @@
#include <linux/spinlock.h>
#include <linux/smp_lock.h>
#include <linux/ac97_codec.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/hardirq.h>
@ -90,8 +92,8 @@ static struct au1550_state {
int no_vra; /* do not use VRA */
spinlock_t lock;
struct semaphore open_sem;
struct semaphore sem;
struct mutex open_mutex;
struct mutex sem;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1044,7 +1046,7 @@ au1550_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
count *= db->cnt_factor;
down(&s->sem);
mutex_lock(&s->sem);
add_wait_queue(&db->wait, &wait);
while (count > 0) {
@ -1064,14 +1066,14 @@ au1550_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->sem);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out2;
}
down(&s->sem);
mutex_lock(&s->sem);
}
} while (avail <= 0);
@ -1099,7 +1101,7 @@ au1550_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
} /* while (count > 0) */
out:
up(&s->sem);
mutex_unlock(&s->sem);
out2:
remove_wait_queue(&db->wait, &wait);
set_current_state(TASK_RUNNING);
@ -1125,7 +1127,7 @@ au1550_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
count *= db->cnt_factor;
down(&s->sem);
mutex_lock(&s->sem);
add_wait_queue(&db->wait, &wait);
while (count > 0) {
@ -1143,14 +1145,14 @@ au1550_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->sem);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out2;
}
down(&s->sem);
mutex_lock(&s->sem);
}
} while (avail <= 0);
@ -1196,7 +1198,7 @@ au1550_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
} /* while (count > 0) */
out:
up(&s->sem);
mutex_unlock(&s->sem);
out2:
remove_wait_queue(&db->wait, &wait);
set_current_state(TASK_RUNNING);
@ -1253,7 +1255,7 @@ au1550_mmap(struct file *file, struct vm_area_struct *vma)
int ret = 0;
lock_kernel();
down(&s->sem);
mutex_lock(&s->sem);
if (vma->vm_flags & VM_WRITE)
db = &s->dma_dac;
else if (vma->vm_flags & VM_READ)
@ -1279,7 +1281,7 @@ au1550_mmap(struct file *file, struct vm_area_struct *vma)
vma->vm_flags &= ~VM_IO;
db->mapped = 1;
out:
up(&s->sem);
mutex_unlock(&s->sem);
unlock_kernel();
return ret;
}
@ -1790,21 +1792,21 @@ au1550_open(struct inode *inode, struct file *file)
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
stop_dac(s);
@ -1840,8 +1842,8 @@ au1550_open(struct inode *inode, struct file *file)
}
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
init_MUTEX(&s->sem);
mutex_unlock(&s->open_mutex);
mutex_init(&s->sem);
return 0;
}
@ -1858,7 +1860,7 @@ au1550_release(struct inode *inode, struct file *file)
lock_kernel();
}
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
kfree(s->dma_dac.rawbuf);
@ -1870,7 +1872,7 @@ au1550_release(struct inode *inode, struct file *file)
s->dma_adc.rawbuf = NULL;
}
s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -1902,7 +1904,7 @@ au1550_probe(void)
init_waitqueue_head(&s->dma_adc.wait);
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->codec = ac97_alloc_codec();

Просмотреть файл

@ -32,6 +32,8 @@
#include <linux/soundcard.h>
#include <linux/slab.h>
#include <linux/kdev_t.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/io.h>
@ -108,7 +110,7 @@ struct btaudio {
/* locking */
int users;
struct semaphore lock;
struct mutex lock;
/* risc instructions */
unsigned int risc_size;
@ -440,7 +442,7 @@ static struct file_operations btaudio_mixer_fops = {
static int btaudio_dsp_open(struct inode *inode, struct file *file,
struct btaudio *bta, int analog)
{
down(&bta->lock);
mutex_lock(&bta->lock);
if (bta->users)
goto busy;
bta->users++;
@ -452,11 +454,11 @@ static int btaudio_dsp_open(struct inode *inode, struct file *file,
bta->read_count = 0;
bta->sampleshift = 0;
up(&bta->lock);
mutex_unlock(&bta->lock);
return 0;
busy:
up(&bta->lock);
mutex_unlock(&bta->lock);
return -EBUSY;
}
@ -496,11 +498,11 @@ static int btaudio_dsp_release(struct inode *inode, struct file *file)
{
struct btaudio *bta = file->private_data;
down(&bta->lock);
mutex_lock(&bta->lock);
if (bta->recording)
stop_recording(bta);
bta->users--;
up(&bta->lock);
mutex_unlock(&bta->lock);
return 0;
}
@ -513,7 +515,7 @@ static ssize_t btaudio_dsp_read(struct file *file, char __user *buffer,
DECLARE_WAITQUEUE(wait, current);
add_wait_queue(&bta->readq, &wait);
down(&bta->lock);
mutex_lock(&bta->lock);
while (swcount > 0) {
if (0 == bta->read_count) {
if (!bta->recording) {
@ -528,10 +530,10 @@ static ssize_t btaudio_dsp_read(struct file *file, char __user *buffer,
ret = -EAGAIN;
break;
}
up(&bta->lock);
mutex_unlock(&bta->lock);
current->state = TASK_INTERRUPTIBLE;
schedule();
down(&bta->lock);
mutex_lock(&bta->lock);
if(signal_pending(current)) {
if (0 == ret)
ret = -EINTR;
@ -604,7 +606,7 @@ static ssize_t btaudio_dsp_read(struct file *file, char __user *buffer,
if (bta->read_offset == bta->buf_size)
bta->read_offset = 0;
}
up(&bta->lock);
mutex_unlock(&bta->lock);
remove_wait_queue(&bta->readq, &wait);
current->state = TASK_RUNNING;
return ret;
@ -651,10 +653,10 @@ static int btaudio_dsp_ioctl(struct inode *inode, struct file *file,
bta->decimation = 0;
}
if (bta->recording) {
down(&bta->lock);
mutex_lock(&bta->lock);
stop_recording(bta);
start_recording(bta);
up(&bta->lock);
mutex_unlock(&bta->lock);
}
/* fall through */
case SOUND_PCM_READ_RATE:
@ -716,10 +718,10 @@ static int btaudio_dsp_ioctl(struct inode *inode, struct file *file,
else
bta->bits = 16;
if (bta->recording) {
down(&bta->lock);
mutex_lock(&bta->lock);
stop_recording(bta);
start_recording(bta);
up(&bta->lock);
mutex_unlock(&bta->lock);
}
}
if (debug)
@ -736,9 +738,9 @@ static int btaudio_dsp_ioctl(struct inode *inode, struct file *file,
case SNDCTL_DSP_RESET:
if (bta->recording) {
down(&bta->lock);
mutex_lock(&bta->lock);
stop_recording(bta);
up(&bta->lock);
mutex_unlock(&bta->lock);
}
return 0;
case SNDCTL_DSP_GETBLKSIZE:
@ -941,7 +943,7 @@ static int __devinit btaudio_probe(struct pci_dev *pci_dev,
if (rate)
bta->rate = rate;
init_MUTEX(&bta->lock);
mutex_init(&bta->lock);
init_waitqueue_head(&bta->readq);
if (-1 != latency) {

Просмотреть файл

@ -138,6 +138,8 @@
#endif
#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
#include <linux/gameport.h>
#include <linux/mutex.h>
#endif
/* --------------------------------------------------------------------- */
@ -392,7 +394,7 @@ struct cm_state {
unsigned char fmt, enable;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -2825,21 +2827,21 @@ static int cm_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
if (file->f_mode & FMODE_READ) {
s->status &= ~DO_BIGENDIAN_R;
@ -2867,7 +2869,7 @@ static int cm_open(struct inode *inode, struct file *file)
}
set_fmt(s, fmtm, fmts);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2879,7 +2881,7 @@ static int cm_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
@ -2903,7 +2905,7 @@ static int cm_release(struct inode *inode, struct file *file)
s->status &= ~DO_BIGENDIAN_R;
}
s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -3080,7 +3082,7 @@ static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id
init_waitqueue_head(&s->dma_adc.wait);
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->magic = CM_MAGIC;
s->dev = pcidev;

Просмотреть файл

@ -90,6 +90,7 @@
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/ac97_codec.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/dma.h>
@ -238,7 +239,7 @@ struct cs_state {
struct cs_card *card; /* Card info */
/* single open lock mechanism, only used for recording */
struct semaphore open_sem;
struct mutex open_mutex;
wait_queue_head_t open_wait;
/* file mode */
@ -297,7 +298,7 @@ struct cs_state {
unsigned subdivision;
} dmabuf;
/* Guard against mmap/write/read races */
struct semaphore sem;
struct mutex sem;
};
struct cs_card {
@ -375,7 +376,7 @@ struct cs_card {
unsigned char ibuf[CS_MIDIINBUF];
unsigned char obuf[CS_MIDIOUTBUF];
mode_t open_mode;
struct semaphore open_sem;
struct mutex open_mutex;
} midi;
struct cs46xx_pm pm;
};
@ -1428,9 +1429,9 @@ static int prog_dmabuf(struct cs_state *state)
{
int ret;
down(&state->sem);
mutex_lock(&state->sem);
ret = __prog_dmabuf(state);
up(&state->sem);
mutex_unlock(&state->sem);
return ret;
}
@ -1831,17 +1832,17 @@ static int cs_midi_open(struct inode *inode, struct file *file)
file->private_data = card;
/* wait for device to become free */
down(&card->midi.open_sem);
mutex_lock(&card->midi.open_mutex);
while (card->midi.open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&card->midi.open_sem);
mutex_unlock(&card->midi.open_mutex);
return -EBUSY;
}
up(&card->midi.open_sem);
mutex_unlock(&card->midi.open_mutex);
interruptible_sleep_on(&card->midi.open_wait);
if (signal_pending(current))
return -ERESTARTSYS;
down(&card->midi.open_sem);
mutex_lock(&card->midi.open_mutex);
}
spin_lock_irqsave(&card->midi.lock, flags);
if (!(card->midi.open_mode & (FMODE_READ | FMODE_WRITE))) {
@ -1859,7 +1860,7 @@ static int cs_midi_open(struct inode *inode, struct file *file)
}
spin_unlock_irqrestore(&card->midi.lock, flags);
card->midi.open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE));
up(&card->midi.open_sem);
mutex_unlock(&card->midi.open_mutex);
return 0;
}
@ -1891,9 +1892,9 @@ static int cs_midi_release(struct inode *inode, struct file *file)
remove_wait_queue(&card->midi.owait, &wait);
current->state = TASK_RUNNING;
}
down(&card->midi.open_sem);
mutex_lock(&card->midi.open_mutex);
card->midi.open_mode &= (~(file->f_mode & (FMODE_READ | FMODE_WRITE)));
up(&card->midi.open_sem);
mutex_unlock(&card->midi.open_mutex);
wake_up(&card->midi.open_wait);
return 0;
}
@ -2081,7 +2082,7 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
if (!access_ok(VERIFY_WRITE, buffer, count))
return -EFAULT;
down(&state->sem);
mutex_lock(&state->sem);
if (!dmabuf->ready && (ret = __prog_dmabuf(state)))
goto out2;
@ -2114,13 +2115,13 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
if (!ret) ret = -EAGAIN;
goto out;
}
up(&state->sem);
mutex_unlock(&state->sem);
schedule();
if (signal_pending(current)) {
if(!ret) ret = -ERESTARTSYS;
goto out;
}
down(&state->sem);
mutex_lock(&state->sem);
if (dmabuf->mapped)
{
if(!ret)
@ -2155,7 +2156,7 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
out:
remove_wait_queue(&state->dmabuf.wait, &wait);
out2:
up(&state->sem);
mutex_unlock(&state->sem);
set_current_state(TASK_RUNNING);
CS_DBGOUT(CS_WAVE_READ | CS_FUNCTION, 4,
printk("cs46xx: cs_read()- %zd\n",ret) );
@ -2184,7 +2185,7 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
return -EFAULT;
dmabuf = &state->dmabuf;
down(&state->sem);
mutex_lock(&state->sem);
if (dmabuf->mapped)
{
ret = -ENXIO;
@ -2240,13 +2241,13 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
if (!ret) ret = -EAGAIN;
goto out;
}
up(&state->sem);
mutex_unlock(&state->sem);
schedule();
if (signal_pending(current)) {
if(!ret) ret = -ERESTARTSYS;
goto out;
}
down(&state->sem);
mutex_lock(&state->sem);
if (dmabuf->mapped)
{
if(!ret)
@ -2278,7 +2279,7 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
start_dac(state);
}
out:
up(&state->sem);
mutex_unlock(&state->sem);
remove_wait_queue(&state->dmabuf.wait, &wait);
set_current_state(TASK_RUNNING);
@ -2411,7 +2412,7 @@ static int cs_mmap(struct file *file, struct vm_area_struct *vma)
goto out;
}
down(&state->sem);
mutex_lock(&state->sem);
dmabuf = &state->dmabuf;
if (cs4x_pgoff(vma) != 0)
{
@ -2438,7 +2439,7 @@ static int cs_mmap(struct file *file, struct vm_area_struct *vma)
CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_mmap()-\n") );
out:
up(&state->sem);
mutex_unlock(&state->sem);
return ret;
}
@ -3200,7 +3201,7 @@ static int cs_open(struct inode *inode, struct file *file)
if (state == NULL)
return -ENOMEM;
memset(state, 0, sizeof(struct cs_state));
init_MUTEX(&state->sem);
mutex_init(&state->sem);
dmabuf = &state->dmabuf;
dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
if(dmabuf->pbuf==NULL)
@ -3241,10 +3242,10 @@ static int cs_open(struct inode *inode, struct file *file)
state->virt = 0;
state->magic = CS_STATE_MAGIC;
init_waitqueue_head(&dmabuf->wait);
init_MUTEX(&state->open_sem);
mutex_init(&state->open_mutex);
file->private_data = card;
down(&state->open_sem);
mutex_lock(&state->open_mutex);
/* set default sample format. According to OSS Programmer's Guide /dev/dsp
should be default to unsigned 8-bits, mono, with sample rate 8kHz and
@ -3260,7 +3261,7 @@ static int cs_open(struct inode *inode, struct file *file)
cs_set_divisor(dmabuf);
state->open_mode |= FMODE_READ;
up(&state->open_sem);
mutex_unlock(&state->open_mutex);
}
if(file->f_mode & FMODE_WRITE)
{
@ -3271,7 +3272,7 @@ static int cs_open(struct inode *inode, struct file *file)
if (state == NULL)
return -ENOMEM;
memset(state, 0, sizeof(struct cs_state));
init_MUTEX(&state->sem);
mutex_init(&state->sem);
dmabuf = &state->dmabuf;
dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
if(dmabuf->pbuf==NULL)
@ -3312,10 +3313,10 @@ static int cs_open(struct inode *inode, struct file *file)
state->virt = 1;
state->magic = CS_STATE_MAGIC;
init_waitqueue_head(&dmabuf->wait);
init_MUTEX(&state->open_sem);
mutex_init(&state->open_mutex);
file->private_data = card;
down(&state->open_sem);
mutex_lock(&state->open_mutex);
/* set default sample format. According to OSS Programmer's Guide /dev/dsp
should be default to unsigned 8-bits, mono, with sample rate 8kHz and
@ -3331,7 +3332,7 @@ static int cs_open(struct inode *inode, struct file *file)
cs_set_divisor(dmabuf);
state->open_mode |= FMODE_WRITE;
up(&state->open_sem);
mutex_unlock(&state->open_mutex);
if((ret = prog_dmabuf(state)))
return ret;
}
@ -3363,14 +3364,14 @@ static int cs_release(struct inode *inode, struct file *file)
cs_clear_tail(state);
drain_dac(state, file->f_flags & O_NONBLOCK);
/* stop DMA state machine and free DMA buffers/channels */
down(&state->open_sem);
mutex_lock(&state->open_mutex);
stop_dac(state);
dealloc_dmabuf(state);
state->card->free_pcm_channel(state->card, dmabuf->channel->num);
free_page((unsigned long)state->dmabuf.pbuf);
/* we're covered by the open_sem */
up(&state->open_sem);
/* we're covered by the open_mutex */
mutex_unlock(&state->open_mutex);
state->card->states[state->virt] = NULL;
state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
@ -3395,14 +3396,14 @@ static int cs_release(struct inode *inode, struct file *file)
{
CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_READ\n") );
dmabuf = &state->dmabuf;
down(&state->open_sem);
mutex_lock(&state->open_mutex);
stop_adc(state);
dealloc_dmabuf(state);
state->card->free_pcm_channel(state->card, dmabuf->channel->num);
free_page((unsigned long)state->dmabuf.pbuf);
/* we're covered by the open_sem */
up(&state->open_sem);
/* we're covered by the open_mutex */
mutex_unlock(&state->open_mutex);
state->card->states[state->virt] = NULL;
state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
@ -5507,7 +5508,7 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
}
init_waitqueue_head(&card->midi.open_wait);
init_MUTEX(&card->midi.open_sem);
mutex_init(&card->midi.open_mutex);
init_waitqueue_head(&card->midi.iwait);
init_waitqueue_head(&card->midi.owait);
cs461x_pokeBA0(card, BA0_MIDCR, MIDCR_MRST);

Просмотреть файл

@ -157,6 +157,7 @@
#include <linux/gameport.h>
#include <linux/wait.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/page.h>
@ -346,7 +347,7 @@ struct es1370_state {
unsigned sctrl;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -393,7 +394,7 @@ struct es1370_state {
struct gameport *gameport;
#endif
struct semaphore sem;
struct mutex mutex;
};
/* --------------------------------------------------------------------- */
@ -1159,7 +1160,7 @@ static ssize_t es1370_read(struct file *file, char __user *buffer, size_t count,
return -ENXIO;
if (!access_ok(VERIFY_WRITE, buffer, count))
return -EFAULT;
down(&s->sem);
mutex_lock(&s->mutex);
if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
goto out;
@ -1183,14 +1184,14 @@ static ssize_t es1370_read(struct file *file, char __user *buffer, size_t count,
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->mutex);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out;
}
down(&s->sem);
mutex_lock(&s->mutex);
if (s->dma_adc.mapped)
{
ret = -ENXIO;
@ -1215,7 +1216,7 @@ static ssize_t es1370_read(struct file *file, char __user *buffer, size_t count,
start_adc(s);
}
out:
up(&s->sem);
mutex_unlock(&s->mutex);
remove_wait_queue(&s->dma_adc.wait, &wait);
set_current_state(TASK_RUNNING);
return ret;
@ -1235,7 +1236,7 @@ static ssize_t es1370_write(struct file *file, const char __user *buffer, size_t
return -ENXIO;
if (!access_ok(VERIFY_READ, buffer, count))
return -EFAULT;
down(&s->sem);
mutex_lock(&s->mutex);
if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
goto out;
ret = 0;
@ -1263,14 +1264,14 @@ static ssize_t es1370_write(struct file *file, const char __user *buffer, size_t
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->mutex);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out;
}
down(&s->sem);
mutex_lock(&s->mutex);
if (s->dma_dac2.mapped)
{
ret = -ENXIO;
@ -1296,7 +1297,7 @@ static ssize_t es1370_write(struct file *file, const char __user *buffer, size_t
start_dac2(s);
}
out:
up(&s->sem);
mutex_unlock(&s->mutex);
remove_wait_queue(&s->dma_dac2.wait, &wait);
set_current_state(TASK_RUNNING);
return ret;
@ -1348,7 +1349,7 @@ static int es1370_mmap(struct file *file, struct vm_area_struct *vma)
VALIDATE_STATE(s);
lock_kernel();
down(&s->sem);
mutex_lock(&s->mutex);
if (vma->vm_flags & VM_WRITE) {
if ((ret = prog_dmabuf_dac2(s)) != 0) {
goto out;
@ -1380,7 +1381,7 @@ static int es1370_mmap(struct file *file, struct vm_area_struct *vma)
}
db->mapped = 1;
out:
up(&s->sem);
mutex_unlock(&s->mutex);
unlock_kernel();
return ret;
}
@ -1752,21 +1753,21 @@ static int es1370_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_READ|FMODE_WRITE)))
@ -1793,8 +1794,8 @@ static int es1370_open(struct inode *inode, struct file *file)
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
init_MUTEX(&s->sem);
mutex_unlock(&s->open_mutex);
mutex_init(&s->mutex);
return nonseekable_open(inode, file);
}
@ -1806,7 +1807,7 @@ static int es1370_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac2(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac2(s);
synchronize_irq(s->irq);
@ -1818,7 +1819,7 @@ static int es1370_release(struct inode *inode, struct file *file)
}
s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2198,21 +2199,21 @@ static int es1370_open_dac(struct inode *inode, struct file *file)
return -EINVAL;
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & FMODE_DAC) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
s->dma_dac1.ossfragshift = s->dma_dac1.ossmaxfrags = s->dma_dac1.subdivision = 0;
s->dma_dac1.enabled = 1;
@ -2227,7 +2228,7 @@ static int es1370_open_dac(struct inode *inode, struct file *file)
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= FMODE_DAC;
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2238,12 +2239,12 @@ static int es1370_release_dac(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
lock_kernel();
drain_dac1(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
stop_dac1(s);
dealloc_dmabuf(s, &s->dma_dac1);
s->open_mode &= ~FMODE_DAC;
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2430,21 +2431,21 @@ static int es1370_midi_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -2465,7 +2466,7 @@ static int es1370_midi_open(struct inode *inode, struct file *file)
es1370_handle_midi(s);
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2499,7 +2500,7 @@ static int es1370_midi_release(struct inode *inode, struct file *file)
remove_wait_queue(&s->midi.owait, &wait);
set_current_state(TASK_RUNNING);
}
down(&s->open_sem);
mutex_lock(&s->open_mutex);
s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -2508,7 +2509,7 @@ static int es1370_midi_release(struct inode *inode, struct file *file)
}
spin_unlock_irqrestore(&s->lock, flags);
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2638,7 +2639,7 @@ static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_devic
init_waitqueue_head(&s->open_wait);
init_waitqueue_head(&s->midi.iwait);
init_waitqueue_head(&s->midi.owait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->magic = ES1370_MAGIC;
s->dev = pcidev;

Просмотреть файл

@ -129,6 +129,7 @@
#include <linux/gameport.h>
#include <linux/wait.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/page.h>
@ -419,7 +420,7 @@ struct es1371_state {
unsigned dac1rate, dac2rate, adcrate;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -462,7 +463,7 @@ struct es1371_state {
struct gameport *gameport;
#endif
struct semaphore sem;
struct mutex sem;
};
/* --------------------------------------------------------------------- */
@ -1346,7 +1347,7 @@ static ssize_t es1371_read(struct file *file, char __user *buffer, size_t count,
return -ENXIO;
if (!access_ok(VERIFY_WRITE, buffer, count))
return -EFAULT;
down(&s->sem);
mutex_lock(&s->sem);
if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
goto out2;
@ -1370,14 +1371,14 @@ static ssize_t es1371_read(struct file *file, char __user *buffer, size_t count,
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->sem);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out2;
}
down(&s->sem);
mutex_lock(&s->sem);
if (s->dma_adc.mapped)
{
ret = -ENXIO;
@ -1402,7 +1403,7 @@ static ssize_t es1371_read(struct file *file, char __user *buffer, size_t count,
start_adc(s);
}
out:
up(&s->sem);
mutex_unlock(&s->sem);
out2:
remove_wait_queue(&s->dma_adc.wait, &wait);
set_current_state(TASK_RUNNING);
@ -1423,7 +1424,7 @@ static ssize_t es1371_write(struct file *file, const char __user *buffer, size_t
return -ENXIO;
if (!access_ok(VERIFY_READ, buffer, count))
return -EFAULT;
down(&s->sem);
mutex_lock(&s->sem);
if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
goto out3;
ret = 0;
@ -1451,14 +1452,14 @@ static ssize_t es1371_write(struct file *file, const char __user *buffer, size_t
ret = -EAGAIN;
goto out;
}
up(&s->sem);
mutex_unlock(&s->sem);
schedule();
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
goto out2;
}
down(&s->sem);
mutex_lock(&s->sem);
if (s->dma_dac2.mapped)
{
ret = -ENXIO;
@ -1484,7 +1485,7 @@ static ssize_t es1371_write(struct file *file, const char __user *buffer, size_t
start_dac2(s);
}
out:
up(&s->sem);
mutex_unlock(&s->sem);
out2:
remove_wait_queue(&s->dma_dac2.wait, &wait);
out3:
@ -1538,7 +1539,7 @@ static int es1371_mmap(struct file *file, struct vm_area_struct *vma)
VALIDATE_STATE(s);
lock_kernel();
down(&s->sem);
mutex_lock(&s->sem);
if (vma->vm_flags & VM_WRITE) {
if ((ret = prog_dmabuf_dac2(s)) != 0) {
@ -1571,7 +1572,7 @@ static int es1371_mmap(struct file *file, struct vm_area_struct *vma)
}
db->mapped = 1;
out:
up(&s->sem);
mutex_unlock(&s->sem);
unlock_kernel();
return ret;
}
@ -1938,21 +1939,21 @@ static int es1371_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
if (file->f_mode & FMODE_READ) {
s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
@ -1982,8 +1983,8 @@ static int es1371_open(struct inode *inode, struct file *file)
outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
init_MUTEX(&s->sem);
mutex_unlock(&s->open_mutex);
mutex_init(&s->sem);
return nonseekable_open(inode, file);
}
@ -1995,7 +1996,7 @@ static int es1371_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac2(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac2(s);
dealloc_dmabuf(s, &s->dma_dac2);
@ -2005,7 +2006,7 @@ static int es1371_release(struct inode *inode, struct file *file)
dealloc_dmabuf(s, &s->dma_adc);
}
s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -2377,21 +2378,21 @@ static int es1371_open_dac(struct inode *inode, struct file *file)
return -EINVAL;
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & FMODE_DAC) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
s->dma_dac1.ossfragshift = s->dma_dac1.ossmaxfrags = s->dma_dac1.subdivision = 0;
s->dma_dac1.enabled = 1;
@ -2405,7 +2406,7 @@ static int es1371_open_dac(struct inode *inode, struct file *file)
outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= FMODE_DAC;
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2416,11 +2417,11 @@ static int es1371_release_dac(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
lock_kernel();
drain_dac1(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
stop_dac1(s);
dealloc_dmabuf(s, &s->dma_dac1);
s->open_mode &= ~FMODE_DAC;
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -2608,21 +2609,21 @@ static int es1371_midi_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -2643,7 +2644,7 @@ static int es1371_midi_open(struct inode *inode, struct file *file)
es1371_handle_midi(s);
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2676,7 +2677,7 @@ static int es1371_midi_release(struct inode *inode, struct file *file)
remove_wait_queue(&s->midi.owait, &wait);
set_current_state(TASK_RUNNING);
}
down(&s->open_sem);
mutex_lock(&s->open_mutex);
s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -2684,7 +2685,7 @@ static int es1371_midi_release(struct inode *inode, struct file *file)
outl(s->ctrl, s->io+ES1371_REG_CONTROL);
}
spin_unlock_irqrestore(&s->lock, flags);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -2884,7 +2885,7 @@ static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_devic
init_waitqueue_head(&s->open_wait);
init_waitqueue_head(&s->midi.iwait);
init_waitqueue_head(&s->midi.owait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->magic = ES1371_MAGIC;
s->dev = pcidev;

Просмотреть файл

@ -105,6 +105,8 @@
#include <linux/gameport.h>
#include <linux/wait.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/page.h>
@ -191,7 +193,7 @@ struct solo1_state {
unsigned ena;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1581,7 +1583,7 @@ static int solo1_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
outb(0, s->iobase+6); /* disable DMA */
@ -1595,7 +1597,7 @@ static int solo1_release(struct inode *inode, struct file *file)
}
s->open_mode &= ~(FMODE_READ | FMODE_WRITE);
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -1624,21 +1626,21 @@ static int solo1_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & (FMODE_READ | FMODE_WRITE)) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
s->fmt = AFMT_U8;
s->channels = 1;
@ -1650,7 +1652,7 @@ static int solo1_open(struct inode *inode, struct file *file)
s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
s->dma_dac.enabled = 1;
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
prog_codec(s);
return nonseekable_open(inode, file);
}
@ -1911,21 +1913,21 @@ static int solo1_midi_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -1951,7 +1953,7 @@ static int solo1_midi_open(struct inode *inode, struct file *file)
}
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -1985,7 +1987,7 @@ static int solo1_midi_release(struct inode *inode, struct file *file)
remove_wait_queue(&s->midi.owait, &wait);
set_current_state(TASK_RUNNING);
}
down(&s->open_sem);
mutex_lock(&s->open_mutex);
s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -1994,7 +1996,7 @@ static int solo1_midi_release(struct inode *inode, struct file *file)
}
spin_unlock_irqrestore(&s->lock, flags);
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2132,24 +2134,24 @@ static int solo1_dmfm_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & FMODE_DMFM) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
if (!request_region(s->sbbase, FMSYNTH_EXTENT, "ESS Solo1")) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
printk(KERN_ERR "solo1: FM synth io ports in use, opl3 loaded?\n");
return -EBUSY;
}
@ -2161,7 +2163,7 @@ static int solo1_dmfm_open(struct inode *inode, struct file *file)
outb(5, s->sbbase+2);
outb(1, s->sbbase+3); /* enable OPL3 */
s->open_mode |= FMODE_DMFM;
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2172,7 +2174,7 @@ static int solo1_dmfm_release(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
lock_kernel();
down(&s->open_sem);
mutex_lock(&s->open_mutex);
s->open_mode &= ~FMODE_DMFM;
for (regb = 0xb0; regb < 0xb9; regb++) {
outb(regb, s->sbbase);
@ -2182,7 +2184,7 @@ static int solo1_dmfm_release(struct inode *inode, struct file *file)
}
release_region(s->sbbase, FMSYNTH_EXTENT);
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2362,7 +2364,7 @@ static int __devinit solo1_probe(struct pci_dev *pcidev, const struct pci_device
init_waitqueue_head(&s->open_wait);
init_waitqueue_head(&s->midi.iwait);
init_waitqueue_head(&s->midi.owait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->magic = SOLO1_MAGIC;
s->dev = pcidev;

Просмотреть файл

@ -43,6 +43,7 @@
#include <linux/interrupt.h>
#include <linux/proc_fs.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/io.h>
@ -185,7 +186,7 @@ struct forte_chip {
unsigned long iobase;
int irq;
struct semaphore open_sem; /* Device access */
struct mutex open_mutex; /* Device access */
spinlock_t lock; /* State */
spinlock_t ac97_lock;
@ -1242,13 +1243,13 @@ forte_dsp_open (struct inode *inode, struct file *file)
struct forte_chip *chip = forte; /* FIXME: HACK FROM HELL! */
if (file->f_flags & O_NONBLOCK) {
if (down_trylock (&chip->open_sem)) {
if (!mutex_trylock(&chip->open_mutex)) {
DPRINTK ("%s: returning -EAGAIN\n", __FUNCTION__);
return -EAGAIN;
}
}
else {
if (down_interruptible (&chip->open_sem)) {
if (mutex_lock_interruptible(&chip->open_mutex)) {
DPRINTK ("%s: returning -ERESTARTSYS\n", __FUNCTION__);
return -ERESTARTSYS;
}
@ -1302,7 +1303,7 @@ forte_dsp_release (struct inode *inode, struct file *file)
spin_unlock_irq (&chip->lock);
}
up (&chip->open_sem);
mutex_unlock(&chip->open_mutex);
return ret;
}
@ -2011,7 +2012,7 @@ forte_probe (struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
memset (chip, 0, sizeof (struct forte_chip));
chip->pci_dev = pci_dev;
init_MUTEX(&chip->open_sem);
mutex_init(&chip->open_mutex);
spin_lock_init (&chip->lock);
spin_lock_init (&chip->ac97_lock);

Просмотреть файл

@ -32,6 +32,8 @@
#include <linux/dma-mapping.h>
#include <linux/sound.h>
#include <linux/soundcard.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/sgi/hpc3.h>
@ -92,7 +94,7 @@ struct hal2_codec {
wait_queue_head_t dma_wait;
spinlock_t lock;
struct semaphore sem;
struct mutex sem;
int usecount; /* recording and playback are
* independent */
@ -1178,7 +1180,7 @@ static ssize_t hal2_read(struct file *file, char *buffer,
if (!count)
return 0;
if (down_interruptible(&adc->sem))
if (mutex_lock_interruptible(&adc->sem))
return -EINTR;
if (file->f_flags & O_NONBLOCK) {
err = hal2_get_buffer(hal2, buffer, count);
@ -1217,7 +1219,7 @@ static ssize_t hal2_read(struct file *file, char *buffer,
}
} while (count > 0 && err >= 0);
}
up(&adc->sem);
mutex_unlock(&adc->sem);
return err;
}
@ -1232,7 +1234,7 @@ static ssize_t hal2_write(struct file *file, const char *buffer,
if (!count)
return 0;
if (down_interruptible(&dac->sem))
if (mutex_lock_interruptible(&dac->sem))
return -EINTR;
if (file->f_flags & O_NONBLOCK) {
err = hal2_add_buffer(hal2, buf, count);
@ -1271,7 +1273,7 @@ static ssize_t hal2_write(struct file *file, const char *buffer,
}
} while (count > 0 && err >= 0);
}
up(&dac->sem);
mutex_unlock(&dac->sem);
return err;
}
@ -1356,20 +1358,20 @@ static int hal2_release(struct inode *inode, struct file *file)
if (file->f_mode & FMODE_READ) {
struct hal2_codec *adc = &hal2->adc;
down(&adc->sem);
mutex_lock(&adc->sem);
hal2_stop_adc(hal2);
hal2_free_adc_dmabuf(adc);
adc->usecount--;
up(&adc->sem);
mutex_unlock(&adc->sem);
}
if (file->f_mode & FMODE_WRITE) {
struct hal2_codec *dac = &hal2->dac;
down(&dac->sem);
mutex_lock(&dac->sem);
hal2_sync_dac(hal2);
hal2_free_dac_dmabuf(dac);
dac->usecount--;
up(&dac->sem);
mutex_unlock(&dac->sem);
}
return 0;
@ -1400,7 +1402,7 @@ static void hal2_init_codec(struct hal2_codec *codec, struct hpc3_regs *hpc3,
codec->pbus.pbusnr = index;
codec->pbus.pbus = &hpc3->pbdma[index];
init_waitqueue_head(&codec->dma_wait);
init_MUTEX(&codec->sem);
mutex_init(&codec->sem);
spin_lock_init(&codec->lock);
}

Просмотреть файл

@ -100,6 +100,8 @@
#include <linux/smp_lock.h>
#include <linux/ac97_codec.h>
#include <linux/bitops.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#define DRIVER_VERSION "1.01"
@ -331,7 +333,7 @@ struct i810_state {
struct i810_card *card; /* Card info */
/* single open lock mechanism, only used for recording */
struct semaphore open_sem;
struct mutex open_mutex;
wait_queue_head_t open_wait;
/* file mode */
@ -2597,7 +2599,7 @@ found_virt:
state->card = card;
state->magic = I810_STATE_MAGIC;
init_waitqueue_head(&dmabuf->wait);
init_MUTEX(&state->open_sem);
mutex_init(&state->open_mutex);
file->private_data = state;
dmabuf->trigger = 0;
@ -3213,7 +3215,7 @@ static void __devinit i810_configure_clocking (void)
state->card = card;
state->magic = I810_STATE_MAGIC;
init_waitqueue_head(&dmabuf->wait);
init_MUTEX(&state->open_sem);
mutex_init(&state->open_mutex);
dmabuf->fmt = I810_FMT_STEREO | I810_FMT_16BIT;
dmabuf->trigger = PCM_ENABLE_OUTPUT;
i810_set_spdif_output(state, -1, 0);

Просмотреть файл

@ -71,6 +71,8 @@
#include <linux/smp_lock.h>
#include <linux/ac97_codec.h>
#include <linux/interrupt.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <asm/uaccess.h>
@ -304,7 +306,7 @@ struct it8172_state {
unsigned dacrate, adcrate;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1801,21 +1803,21 @@ static int it8172_open(struct inode *inode, struct file *file)
}
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
@ -1850,7 +1852,7 @@ static int it8172_open(struct inode *inode, struct file *file)
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE));
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -1864,7 +1866,7 @@ static int it8172_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
dealloc_dmabuf(s, &s->dma_dac);
@ -1874,7 +1876,7 @@ static int it8172_release(struct inode *inode, struct file *file)
dealloc_dmabuf(s, &s->dma_adc);
}
s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -1997,7 +1999,7 @@ static int __devinit it8172_probe(struct pci_dev *pcidev,
init_waitqueue_head(&s->dma_adc.wait);
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->dev = pcidev;
s->io = pci_resource_start(pcidev, 0);

Просмотреть файл

@ -223,6 +223,8 @@
#include <linux/reboot.h>
#include <linux/bitops.h>
#include <linux/wait.h>
#include <linux/mutex.h>
#include <asm/current.h>
#include <asm/dma.h>
@ -397,7 +399,7 @@ struct ess_state {
/* this locks around the oss state in the driver */
spinlock_t lock;
/* only let 1 be opening at a time */
struct semaphore open_sem;
struct mutex open_mutex;
wait_queue_head_t open_wait;
mode_t open_mode;
@ -3020,26 +3022,26 @@ ess_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EWOULDBLOCK;
}
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
interruptible_sleep_on(&s->open_wait);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
/* under semaphore.. */
if ((s->card->dmapages==NULL) && allocate_buffers(s)) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -ENOMEM;
}
/* we're covered by the open_sem */
/* we're covered by the open_mutex */
if( ! s->card->dsps_open ) {
maestro_power(s->card,ACPI_D0);
start_bob(s);
@ -3076,7 +3078,7 @@ ess_open(struct inode *inode, struct file *file)
set_fmt(s, fmtm, fmts);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -3089,7 +3091,7 @@ ess_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
}
@ -3098,7 +3100,7 @@ ess_release(struct inode *inode, struct file *file)
}
s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
/* we're covered by the open_sem */
/* we're covered by the open_mutex */
M_printk("maestro: %d dsps now alive\n",s->card->dsps_open-1);
if( --s->card->dsps_open <= 0) {
s->card->dsps_open = 0;
@ -3106,7 +3108,7 @@ ess_release(struct inode *inode, struct file *file)
free_buffers(s);
maestro_power(s->card,ACPI_D2);
}
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -3466,7 +3468,7 @@ maestro_probe(struct pci_dev *pcidev,const struct pci_device_id *pdid)
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
spin_lock_init(&s->lock);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
s->magic = ESS_STATE_MAGIC;
s->apu[0] = 6*i;

Просмотреть файл

@ -144,6 +144,8 @@
#include <linux/spinlock.h>
#include <linux/ac97_codec.h>
#include <linux/wait.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/dma.h>
@ -205,7 +207,7 @@ struct m3_state {
when irqhandler uses s->lock
and m3_assp_read uses card->lock ?
*/
struct semaphore open_sem;
struct mutex open_mutex;
wait_queue_head_t open_wait;
mode_t open_mode;
@ -2013,17 +2015,17 @@ static int m3_open(struct inode *inode, struct file *file)
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EWOULDBLOCK;
}
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
interruptible_sleep_on(&s->open_wait);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&c->lock, flags);
@ -2047,7 +2049,7 @@ static int m3_open(struct inode *inode, struct file *file)
set_fmt(s, fmtm, fmts);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
spin_unlock_irqrestore(&c->lock, flags);
return nonseekable_open(inode, file);
}
@ -2062,7 +2064,7 @@ static int m3_release(struct inode *inode, struct file *file)
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
spin_lock_irqsave(&card->lock, flags);
if (file->f_mode & FMODE_WRITE) {
@ -2083,7 +2085,7 @@ static int m3_release(struct inode *inode, struct file *file)
s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
spin_unlock_irqrestore(&card->lock, flags);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
return 0;
@ -2679,7 +2681,7 @@ static int __devinit m3_probe(struct pci_dev *pci_dev, const struct pci_device_i
init_waitqueue_head(&s->dma_adc.wait);
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
init_MUTEX(&(s->open_sem));
mutex_init(&(s->open_mutex));
s->magic = M3_STATE_MAGIC;
m3_assp_client_init(s);

Просмотреть файл

@ -78,6 +78,8 @@
#include <linux/spinlock.h>
#include <linux/smp_lock.h>
#include <linux/ac97_codec.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <asm/uaccess.h>
@ -198,7 +200,7 @@ struct vrc5477_ac97_state {
unsigned short extended_status;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1617,22 +1619,22 @@ static int vrc5477_ac97_open(struct inode *inode, struct file *file)
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
@ -1659,7 +1661,7 @@ static int vrc5477_ac97_open(struct inode *inode, struct file *file)
bailout:
spin_unlock_irqrestore(&s->lock, flags);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return ret;
}
@ -1671,7 +1673,7 @@ static int vrc5477_ac97_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
dealloc_dmabuf(s, &s->dma_dac);
@ -1681,7 +1683,7 @@ static int vrc5477_ac97_release(struct inode *inode, struct file *file)
dealloc_dmabuf(s, &s->dma_adc);
}
s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
return 0;
@ -1867,7 +1869,7 @@ static int __devinit vrc5477_ac97_probe(struct pci_dev *pcidev,
init_waitqueue_head(&s->dma_adc.wait);
init_waitqueue_head(&s->dma_dac.wait);
init_waitqueue_head(&s->open_wait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->dev = pcidev;

Просмотреть файл

@ -58,6 +58,7 @@ TODO:
#include <linux/interrupt.h>
#include <linux/poll.h>
#include <linux/wait.h>
#include <linux/mutex.h>
#include <asm/dma.h>
#include <asm/page.h>
@ -326,7 +327,7 @@ typedef struct _rme96xx_info {
/* waiting and locking */
wait_queue_head_t wait;
struct semaphore open_sem;
struct mutex open_mutex;
wait_queue_head_t open_wait;
} dma[RME96xx_MAX_DEVS];
@ -842,7 +843,7 @@ static void busmaster_free(void* ptr,int size) {
static int rme96xx_dmabuf_init(rme96xx_info * s,struct dmabuf* dma,int ioffset,int ooffset) {
init_MUTEX(&dma->open_sem);
mutex_init(&dma->open_mutex);
init_waitqueue_head(&dma->open_wait);
init_waitqueue_head(&dma->wait);
dma->s = s;
@ -1469,21 +1470,21 @@ static int rme96xx_open(struct inode *in, struct file *f)
dma = &s->dma[devnum];
f->private_data = dma;
/* wait for device to become free */
down(&dma->open_sem);
mutex_lock(&dma->open_mutex);
while (dma->open_mode & f->f_mode) {
if (f->f_flags & O_NONBLOCK) {
up(&dma->open_sem);
mutex_unlock(&dma->open_mutex);
return -EBUSY;
}
add_wait_queue(&dma->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&dma->open_sem);
mutex_unlock(&dma->open_mutex);
schedule();
remove_wait_queue(&dma->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&dma->open_sem);
mutex_lock(&dma->open_mutex);
}
COMM ("hardware open")
@ -1492,7 +1493,7 @@ static int rme96xx_open(struct inode *in, struct file *f)
dma->open_mode |= (f->f_mode & (FMODE_READ | FMODE_WRITE));
dma->opened = 1;
up(&dma->open_sem);
mutex_unlock(&dma->open_mutex);
DBG(printk("device num %d open finished\n",devnum));
return 0;
@ -1524,7 +1525,7 @@ static int rme96xx_release(struct inode *in, struct file *file)
}
wake_up(&dma->open_wait);
up(&dma->open_sem);
mutex_unlock(&dma->open_mutex);
return 0;
}

Просмотреть файл

@ -116,6 +116,8 @@
#include <linux/spinlock.h>
#include <linux/smp_lock.h>
#include <linux/gameport.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/uaccess.h>
@ -328,7 +330,7 @@ struct sv_state {
unsigned char fmt, enable;
spinlock_t lock;
struct semaphore open_sem;
struct mutex open_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1922,21 +1924,21 @@ static int sv_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
if (file->f_mode & FMODE_READ) {
fmtm &= ~((SV_CFMT_STEREO | SV_CFMT_16BIT) << SV_CFMT_CSHIFT);
@ -1956,7 +1958,7 @@ static int sv_open(struct inode *inode, struct file *file)
}
set_fmt(s, fmtm, fmts);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -1968,7 +1970,7 @@ static int sv_release(struct inode *inode, struct file *file)
lock_kernel();
if (file->f_mode & FMODE_WRITE)
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem);
mutex_lock(&s->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(s);
dealloc_dmabuf(s, &s->dma_dac);
@ -1979,7 +1981,7 @@ static int sv_release(struct inode *inode, struct file *file)
}
s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2167,21 +2169,21 @@ static int sv_midi_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -2210,7 +2212,7 @@ static int sv_midi_open(struct inode *inode, struct file *file)
}
spin_unlock_irqrestore(&s->lock, flags);
s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2248,7 +2250,7 @@ static int sv_midi_release(struct inode *inode, struct file *file)
remove_wait_queue(&s->midi.owait, &wait);
set_current_state(TASK_RUNNING);
}
down(&s->open_sem);
mutex_lock(&s->open_mutex);
s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
spin_lock_irqsave(&s->lock, flags);
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@ -2257,7 +2259,7 @@ static int sv_midi_release(struct inode *inode, struct file *file)
}
spin_unlock_irqrestore(&s->lock, flags);
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2388,21 +2390,21 @@ static int sv_dmfm_open(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
file->private_data = s;
/* wait for device to become free */
down(&s->open_sem);
mutex_lock(&s->open_mutex);
while (s->open_mode & FMODE_DMFM) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return -EBUSY;
}
add_wait_queue(&s->open_wait, &wait);
__set_current_state(TASK_INTERRUPTIBLE);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
schedule();
remove_wait_queue(&s->open_wait, &wait);
set_current_state(TASK_RUNNING);
if (signal_pending(current))
return -ERESTARTSYS;
down(&s->open_sem);
mutex_lock(&s->open_mutex);
}
/* init the stuff */
outb(1, s->iosynth);
@ -2412,7 +2414,7 @@ static int sv_dmfm_open(struct inode *inode, struct file *file)
outb(5, s->iosynth+2);
outb(1, s->iosynth+3); /* enable OPL3 */
s->open_mode |= FMODE_DMFM;
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
return nonseekable_open(inode, file);
}
@ -2423,7 +2425,7 @@ static int sv_dmfm_release(struct inode *inode, struct file *file)
VALIDATE_STATE(s);
lock_kernel();
down(&s->open_sem);
mutex_lock(&s->open_mutex);
s->open_mode &= ~FMODE_DMFM;
for (regb = 0xb0; regb < 0xb9; regb++) {
outb(regb, s->iosynth);
@ -2432,7 +2434,7 @@ static int sv_dmfm_release(struct inode *inode, struct file *file)
outb(0, s->iosynth+3);
}
wake_up(&s->open_wait);
up(&s->open_sem);
mutex_unlock(&s->open_mutex);
unlock_kernel();
return 0;
}
@ -2582,7 +2584,7 @@ static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id
init_waitqueue_head(&s->open_wait);
init_waitqueue_head(&s->midi.iwait);
init_waitqueue_head(&s->midi.owait);
init_MUTEX(&s->open_sem);
mutex_init(&s->open_mutex);
spin_lock_init(&s->lock);
s->magic = SV_MAGIC;
s->dev = pcidev;

Просмотреть файл

@ -76,6 +76,7 @@
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <asm/byteorder.h>
#include <asm/dma.h>
@ -291,9 +292,9 @@ struct cs4297a_state {
unsigned conversion:1; // conversion from 16 to 8 bit in progress
unsigned ena;
spinlock_t lock;
struct semaphore open_sem;
struct semaphore open_sem_adc;
struct semaphore open_sem_dac;
struct mutex open_mutex;
struct mutex open_sem_adc;
struct mutex open_sem_dac;
mode_t open_mode;
wait_queue_head_t open_wait;
wait_queue_head_t open_wait_adc;
@ -2352,20 +2353,20 @@ static int cs4297a_release(struct inode *inode, struct file *file)
if (file->f_mode & FMODE_WRITE) {
drain_dac(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem_dac);
mutex_lock(&s->open_sem_dac);
stop_dac(s);
dealloc_dmabuf(s, &s->dma_dac);
s->open_mode &= ~FMODE_WRITE;
up(&s->open_sem_dac);
mutex_unlock(&s->open_sem_dac);
wake_up(&s->open_wait_dac);
}
if (file->f_mode & FMODE_READ) {
drain_adc(s, file->f_flags & O_NONBLOCK);
down(&s->open_sem_adc);
mutex_lock(&s->open_sem_adc);
stop_adc(s);
dealloc_dmabuf(s, &s->dma_adc);
s->open_mode &= ~FMODE_READ;
up(&s->open_sem_adc);
mutex_unlock(&s->open_sem_adc);
wake_up(&s->open_wait_adc);
}
return 0;
@ -2413,37 +2414,37 @@ static int cs4297a_open(struct inode *inode, struct file *file)
;
}
down(&s->open_sem_dac);
mutex_lock(&s->open_sem_dac);
while (s->open_mode & FMODE_WRITE) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem_dac);
mutex_unlock(&s->open_sem_dac);
return -EBUSY;
}
up(&s->open_sem_dac);
mutex_unlock(&s->open_sem_dac);
interruptible_sleep_on(&s->open_wait_dac);
if (signal_pending(current)) {
printk("open - sig pending\n");
return -ERESTARTSYS;
}
down(&s->open_sem_dac);
mutex_lock(&s->open_sem_dac);
}
}
if (file->f_mode & FMODE_READ) {
down(&s->open_sem_adc);
mutex_lock(&s->open_sem_adc);
while (s->open_mode & FMODE_READ) {
if (file->f_flags & O_NONBLOCK) {
up(&s->open_sem_adc);
mutex_unlock(&s->open_sem_adc);
return -EBUSY;
}
up(&s->open_sem_adc);
mutex_unlock(&s->open_sem_adc);
interruptible_sleep_on(&s->open_wait_adc);
if (signal_pending(current)) {
printk("open - sig pending\n");
return -ERESTARTSYS;
}
down(&s->open_sem_adc);
mutex_lock(&s->open_sem_adc);
}
}
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
@ -2456,7 +2457,7 @@ static int cs4297a_open(struct inode *inode, struct file *file)
s->ena &= ~FMODE_READ;
s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
s->dma_adc.subdivision = 0;
up(&s->open_sem_adc);
mutex_unlock(&s->open_sem_adc);
if (prog_dmabuf_adc(s)) {
CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
@ -2474,7 +2475,7 @@ static int cs4297a_open(struct inode *inode, struct file *file)
s->ena &= ~FMODE_WRITE;
s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
s->dma_dac.subdivision = 0;
up(&s->open_sem_dac);
mutex_unlock(&s->open_sem_dac);
if (prog_dmabuf_dac(s)) {
CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
@ -2631,8 +2632,8 @@ static int __init cs4297a_init(void)
init_waitqueue_head(&s->open_wait);
init_waitqueue_head(&s->open_wait_adc);
init_waitqueue_head(&s->open_wait_dac);
init_MUTEX(&s->open_sem_adc);
init_MUTEX(&s->open_sem_dac);
mutex_init(&s->open_sem_adc);
mutex_init(&s->open_sem_dac);
spin_lock_init(&s->lock);
s->irq = K_INT_SER_1;

Просмотреть файл

@ -190,7 +190,7 @@
*
* Lock order (high->low)
* lock - hardware lock
* open_sem - guard opens
* open_mutex - guard opens
* sem - guard dmabuf, write re-entry etc
*/
@ -216,6 +216,8 @@
#include <linux/pm.h>
#include <linux/gameport.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/dma.h>
@ -349,7 +351,7 @@ struct trident_state {
unsigned chans_num;
unsigned long fmt_flag;
/* Guard against mmap/write/read races */
struct semaphore sem;
struct mutex sem;
};
@ -402,7 +404,7 @@ struct trident_card {
struct trident_card *next;
/* single open lock mechanism, only used for recording */
struct semaphore open_sem;
struct mutex open_mutex;
/* The trident has a certain amount of cross channel interaction
so we use a single per card lock */
@ -1881,7 +1883,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
if (!access_ok(VERIFY_WRITE, buffer, count))
return -EFAULT;
down(&state->sem);
mutex_lock(&state->sem);
if (!dmabuf->ready && (ret = prog_dmabuf_record(state)))
goto out;
@ -1913,7 +1915,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
goto out;
}
up(&state->sem);
mutex_unlock(&state->sem);
/* No matter how much space left in the buffer, */
/* we have to wait until CSO == ESO/2 or CSO == ESO */
/* when address engine interrupts */
@ -1940,7 +1942,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
ret = -ERESTARTSYS;
goto out;
}
down(&state->sem);
mutex_lock(&state->sem);
if (dmabuf->mapped) {
if (!ret)
ret = -ENXIO;
@ -1968,7 +1970,7 @@ trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos
start_adc(state);
}
out:
up(&state->sem);
mutex_unlock(&state->sem);
return ret;
}
@ -1996,7 +1998,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
* Guard against an mmap or ioctl while writing
*/
down(&state->sem);
mutex_lock(&state->sem);
if (dmabuf->mapped) {
ret = -ENXIO;
@ -2045,7 +2047,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
tmo = (dmabuf->dmasize * HZ) / (dmabuf->rate * 2);
tmo >>= sample_shift[dmabuf->fmt];
unlock_set_fmt(state);
up(&state->sem);
mutex_unlock(&state->sem);
/* There are two situations when sleep_on_timeout */
/* returns, one is when the interrupt is serviced */
@ -2073,7 +2075,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
ret = -ERESTARTSYS;
goto out_nolock;
}
down(&state->sem);
mutex_lock(&state->sem);
if (dmabuf->mapped) {
if (!ret)
ret = -ENXIO;
@ -2131,7 +2133,7 @@ trident_write(struct file *file, const char __user *buffer, size_t count, loff_t
start_dac(state);
}
out:
up(&state->sem);
mutex_unlock(&state->sem);
out_nolock:
return ret;
}
@ -2152,24 +2154,24 @@ trident_poll(struct file *file, struct poll_table_struct *wait)
* prog_dmabuf events
*/
down(&state->sem);
mutex_lock(&state->sem);
if (file->f_mode & FMODE_WRITE) {
if (!dmabuf->ready && prog_dmabuf_playback(state)) {
up(&state->sem);
mutex_unlock(&state->sem);
return 0;
}
poll_wait(file, &dmabuf->wait, wait);
}
if (file->f_mode & FMODE_READ) {
if (!dmabuf->ready && prog_dmabuf_record(state)) {
up(&state->sem);
mutex_unlock(&state->sem);
return 0;
}
poll_wait(file, &dmabuf->wait, wait);
}
up(&state->sem);
mutex_unlock(&state->sem);
spin_lock_irqsave(&state->card->lock, flags);
trident_update_ptr(state);
@ -2207,7 +2209,7 @@ trident_mmap(struct file *file, struct vm_area_struct *vma)
* a read or write against an mmap.
*/
down(&state->sem);
mutex_lock(&state->sem);
if (vma->vm_flags & VM_WRITE) {
if ((ret = prog_dmabuf_playback(state)) != 0)
@ -2232,7 +2234,7 @@ trident_mmap(struct file *file, struct vm_area_struct *vma)
dmabuf->mapped = 1;
ret = 0;
out:
up(&state->sem);
mutex_unlock(&state->sem);
return ret;
}
@ -2429,15 +2431,15 @@ trident_ioctl(struct inode *inode, struct file *file,
unlock_set_fmt(state);
break;
}
down(&state->card->open_sem);
mutex_lock(&state->card->open_mutex);
ret = ali_allocate_other_states_resources(state, 6);
if (ret < 0) {
up(&state->card->open_sem);
mutex_unlock(&state->card->open_mutex);
unlock_set_fmt(state);
break;
}
state->card->multi_channel_use_count++;
up(&state->card->open_sem);
mutex_unlock(&state->card->open_mutex);
} else
val = 2; /*yield to 2-channels */
} else
@ -2727,11 +2729,11 @@ trident_open(struct inode *inode, struct file *file)
/* find an available virtual channel (instance of /dev/dsp) */
while (card != NULL) {
down(&card->open_sem);
mutex_lock(&card->open_mutex);
if (file->f_mode & FMODE_READ) {
/* Skip opens on cards that are in 6 channel mode */
if (card->multi_channel_use_count > 0) {
up(&card->open_sem);
mutex_unlock(&card->open_mutex);
card = card->next;
continue;
}
@ -2740,16 +2742,16 @@ trident_open(struct inode *inode, struct file *file)
if (card->states[i] == NULL) {
state = card->states[i] = kmalloc(sizeof(*state), GFP_KERNEL);
if (state == NULL) {
up(&card->open_sem);
mutex_unlock(&card->open_mutex);
return -ENOMEM;
}
memset(state, 0, sizeof(*state));
init_MUTEX(&state->sem);
mutex_init(&state->sem);
dmabuf = &state->dmabuf;
goto found_virt;
}
}
up(&card->open_sem);
mutex_unlock(&card->open_mutex);
card = card->next;
}
/* no more virtual channel avaiable */
@ -2816,7 +2818,7 @@ trident_open(struct inode *inode, struct file *file)
}
state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&card->open_sem);
mutex_unlock(&card->open_mutex);
pr_debug("trident: open virtual channel %d, hard channel %d\n",
state->virt, dmabuf->channel->num);
@ -2845,7 +2847,7 @@ trident_release(struct inode *inode, struct file *file)
state->virt, dmabuf->channel->num);
/* stop DMA state machine and free DMA buffers/channels */
down(&card->open_sem);
mutex_lock(&card->open_mutex);
if (file->f_mode & FMODE_WRITE) {
stop_dac(state);
@ -2878,8 +2880,8 @@ trident_release(struct inode *inode, struct file *file)
card->states[state->virt] = NULL;
kfree(state);
/* we're covered by the open_sem */
up(&card->open_sem);
/* we're covered by the open_mutex */
mutex_unlock(&card->open_mutex);
return 0;
}
@ -4405,7 +4407,7 @@ trident_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
card->banks[BANK_B].addresses = &bank_b_addrs;
card->banks[BANK_B].bitmap = 0UL;
init_MUTEX(&card->open_sem);
mutex_init(&card->open_mutex);
spin_lock_init(&card->lock);
init_timer(&card->timer);

Просмотреть файл

@ -38,7 +38,8 @@
#include <linux/dma-mapping.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/semaphore.h>
#include <linux/mutex.h>
#include "sound_config.h"
#include "dev_table.h"
#include "mpu401.h"
@ -311,8 +312,8 @@ struct via_info {
int mixer_vol; /* 8233/35 volume - not yet implemented */
struct semaphore syscall_sem;
struct semaphore open_sem;
struct mutex syscall_mutex;
struct mutex open_mutex;
/* The 8233/8235 have 4 DX audio channels, two record and
one six channel out. We bind ch_in to DX 1, ch_out to multichannel
@ -505,10 +506,10 @@ static inline int via_syscall_down (struct via_info *card, int nonblock)
nonblock = 0;
if (nonblock) {
if (down_trylock (&card->syscall_sem))
if (!mutex_trylock(&card->syscall_mutex))
return -EAGAIN;
} else {
if (down_interruptible (&card->syscall_sem))
if (mutex_lock_interruptible(&card->syscall_mutex))
return -ERESTARTSYS;
}
@ -1609,7 +1610,7 @@ static int via_mixer_ioctl (struct inode *inode, struct file *file, unsigned int
#endif
rc = codec->mixer_ioctl(codec, cmd, arg);
up (&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
out:
DPRINTK ("EXIT, returning %d\n", rc);
@ -2228,7 +2229,7 @@ static int via_dsp_mmap(struct file *file, struct vm_area_struct *vma)
if (wr)
card->ch_out.is_mapped = 1;
up (&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
rc = 0;
out:
@ -2256,7 +2257,7 @@ handle_one_block:
/* Thomas Sailer:
* But also to ourselves, release semaphore if we do so */
if (need_resched()) {
up(&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
schedule ();
ret = via_syscall_down (card, nonblock);
if (ret)
@ -2286,7 +2287,7 @@ handle_one_block:
break;
}
up(&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
DPRINTK ("Sleeping on block %d\n", n);
schedule();
@ -2402,7 +2403,7 @@ static ssize_t via_dsp_read(struct file *file, char __user *buffer, size_t count
rc = via_dsp_do_read (card, buffer, count, nonblock);
out_up:
up (&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
out:
DPRINTK ("EXIT, returning %ld\n",(long) rc);
return rc;
@ -2426,7 +2427,7 @@ handle_one_block:
/* Thomas Sailer:
* But also to ourselves, release semaphore if we do so */
if (need_resched()) {
up(&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
schedule ();
ret = via_syscall_down (card, nonblock);
if (ret)
@ -2456,7 +2457,7 @@ handle_one_block:
break;
}
up(&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
DPRINTK ("Sleeping on page %d, tmp==%d, ir==%d\n", n, tmp, chan->is_record);
schedule();
@ -2585,7 +2586,7 @@ static ssize_t via_dsp_write(struct file *file, const char __user *buffer, size_
rc = via_dsp_do_write (card, buffer, count, nonblock);
out_up:
up (&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
out:
DPRINTK ("EXIT, returning %ld\n",(long) rc);
return rc;
@ -2634,7 +2635,7 @@ static unsigned int via_dsp_poll(struct file *file, struct poll_table_struct *wa
* Sleeps until all playback has been flushed to the audio
* hardware.
*
* Locking: inside card->syscall_sem
* Locking: inside card->syscall_mutex
*/
static int via_dsp_drain_playback (struct via_info *card,
@ -2692,7 +2693,7 @@ static int via_dsp_drain_playback (struct via_info *card,
printk (KERN_ERR "sleeping but not active\n");
#endif
up(&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
DPRINTK ("sleeping, nbufs=%d\n", atomic_read (&chan->n_frags));
schedule();
@ -2748,7 +2749,7 @@ out:
*
* Handles SNDCTL_DSP_GETISPACE and SNDCTL_DSP_GETOSPACE.
*
* Locking: inside card->syscall_sem
* Locking: inside card->syscall_mutex
*/
static int via_dsp_ioctl_space (struct via_info *card,
@ -2793,7 +2794,7 @@ static int via_dsp_ioctl_space (struct via_info *card,
*
* Handles SNDCTL_DSP_GETIPTR and SNDCTL_DSP_GETOPTR.
*
* Locking: inside card->syscall_sem
* Locking: inside card->syscall_mutex
*/
static int via_dsp_ioctl_ptr (struct via_info *card,
@ -3221,7 +3222,7 @@ static int via_dsp_ioctl (struct inode *inode, struct file *file,
break;
}
up (&card->syscall_sem);
mutex_unlock(&card->syscall_mutex);
DPRINTK ("EXIT, returning %d\n", rc);
return rc;
}
@ -3264,12 +3265,12 @@ static int via_dsp_open (struct inode *inode, struct file *file)
match:
if (nonblock) {
if (down_trylock (&card->open_sem)) {
if (!mutex_trylock(&card->open_mutex)) {
DPRINTK ("EXIT, returning -EAGAIN\n");
return -EAGAIN;
}
} else {
if (down_interruptible (&card->open_sem)) {
if (mutex_lock_interruptible(&card->open_mutex)) {
DPRINTK ("EXIT, returning -ERESTARTSYS\n");
return -ERESTARTSYS;
}
@ -3355,8 +3356,8 @@ static int via_dsp_release(struct inode *inode, struct file *file)
via_chan_buffer_free (card, &card->ch_in);
}
up (&card->syscall_sem);
up (&card->open_sem);
mutex_unlock(&card->syscall_mutex);
mutex_unlock(&card->open_mutex);
DPRINTK ("EXIT, returning 0\n");
return 0;
@ -3414,8 +3415,8 @@ static int __devinit via_init_one (struct pci_dev *pdev, const struct pci_device
card->card_num = via_num_cards++;
spin_lock_init (&card->lock);
spin_lock_init (&card->ac97_lock);
init_MUTEX (&card->syscall_sem);
init_MUTEX (&card->open_sem);
mutex_init(&card->syscall_mutex);
mutex_init(&card->open_mutex);
/* we must init these now, in case the intr handler needs them */
via_chan_init_defaults (card, &card->ch_out);

Просмотреть файл

@ -94,7 +94,7 @@
* Open will block until the previous client has closed the
* device, unless O_NONBLOCK is specified.
*
* The semaphore devc->io_sema serializes PCM I/O syscalls. This
* The semaphore devc->io_mutex serializes PCM I/O syscalls. This
* is unnecessary in Linux 2.2, because the kernel lock
* serializes read, write, and ioctl globally, but it's there,
* ready for the brave, new post-kernel-lock world.
@ -105,7 +105,7 @@
* area it owns and update its pointers. See pcm_output() and
* pcm_input() for most of the gory stuff.
*
* devc->mix_sema serializes all mixer ioctls. This is also
* devc->mix_mutex serializes all mixer ioctls. This is also
* redundant because of the kernel lock.
*
* The lowest level lock is lith->lithium_lock. It is a
@ -148,7 +148,8 @@
#include <linux/smp_lock.h>
#include <linux/wait.h>
#include <linux/interrupt.h>
#include <asm/semaphore.h>
#include <linux/mutex.h>
#include <asm/mach-visws/cobalt.h>
#include "sound_config.h"
@ -1447,11 +1448,11 @@ typedef enum vwsnd_port_flags {
*
* port->lock protects: hwstate, flags, swb_[iu]_avail.
*
* devc->io_sema protects: swstate, sw_*, swb_[iu]_idx.
* devc->io_mutex protects: swstate, sw_*, swb_[iu]_idx.
*
* everything else is only written by open/release or
* pcm_{setup,shutdown}(), which are serialized by a
* combination of devc->open_sema and devc->io_sema.
* combination of devc->open_mutex and devc->io_mutex.
*/
typedef struct vwsnd_port {
@ -1507,9 +1508,9 @@ typedef struct vwsnd_dev {
int audio_minor; /* minor number of audio device */
int mixer_minor; /* minor number of mixer device */
struct semaphore open_sema;
struct semaphore io_sema;
struct semaphore mix_sema;
struct mutex open_mutex;
struct mutex io_mutex;
struct mutex mix_mutex;
mode_t open_mode;
wait_queue_head_t open_wait;
@ -1633,7 +1634,7 @@ static __inline__ unsigned int swb_inc_i(vwsnd_port_t *port, int inc)
* mode-setting ioctls have been done, but before the first I/O is
* done.
*
* Locking: called with devc->io_sema held.
* Locking: called with devc->io_mutex held.
*
* Returns 0 on success, -errno on failure.
*/
@ -2319,9 +2320,9 @@ static ssize_t vwsnd_audio_read(struct file *file,
vwsnd_dev_t *devc = file->private_data;
ssize_t ret;
down(&devc->io_sema);
mutex_lock(&devc->io_mutex);
ret = vwsnd_audio_do_read(file, buffer, count, ppos);
up(&devc->io_sema);
mutex_unlock(&devc->io_mutex);
return ret;
}
@ -2394,9 +2395,9 @@ static ssize_t vwsnd_audio_write(struct file *file,
vwsnd_dev_t *devc = file->private_data;
ssize_t ret;
down(&devc->io_sema);
mutex_lock(&devc->io_mutex);
ret = vwsnd_audio_do_write(file, buffer, count, ppos);
up(&devc->io_sema);
mutex_unlock(&devc->io_mutex);
return ret;
}
@ -2891,9 +2892,9 @@ static int vwsnd_audio_ioctl(struct inode *inode,
vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;
int ret;
down(&devc->io_sema);
mutex_lock(&devc->io_mutex);
ret = vwsnd_audio_do_ioctl(inode, file, cmd, arg);
up(&devc->io_sema);
mutex_unlock(&devc->io_mutex);
return ret;
}
@ -2929,9 +2930,9 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)
return -ENODEV;
}
down(&devc->open_sema);
mutex_lock(&devc->open_mutex);
while (devc->open_mode & file->f_mode) {
up(&devc->open_sema);
mutex_unlock(&devc->open_mutex);
if (file->f_flags & O_NONBLOCK) {
DEC_USE_COUNT;
return -EBUSY;
@ -2941,10 +2942,10 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)
DEC_USE_COUNT;
return -ERESTARTSYS;
}
down(&devc->open_sema);
mutex_lock(&devc->open_mutex);
}
devc->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&devc->open_sema);
mutex_unlock(&devc->open_mutex);
/* get default sample format from minor number. */
@ -2960,7 +2961,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)
/* Initialize vwsnd_ports. */
down(&devc->io_sema);
mutex_lock(&devc->io_mutex);
{
if (file->f_mode & FMODE_READ) {
devc->rport.swstate = SW_INITIAL;
@ -2987,7 +2988,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file)
devc->wport.frag_count = 0;
}
}
up(&devc->io_sema);
mutex_unlock(&devc->io_mutex);
file->private_data = devc;
DBGRV();
@ -3005,7 +3006,7 @@ static int vwsnd_audio_release(struct inode *inode, struct file *file)
int err = 0;
lock_kernel();
down(&devc->io_sema);
mutex_lock(&devc->io_mutex);
{
DBGEV("(inode=0x%p, file=0x%p)\n", inode, file);
@ -3022,13 +3023,13 @@ static int vwsnd_audio_release(struct inode *inode, struct file *file)
if (wport)
wport->swstate = SW_OFF;
}
up(&devc->io_sema);
mutex_unlock(&devc->io_mutex);
down(&devc->open_sema);
mutex_lock(&devc->open_mutex);
{
devc->open_mode &= ~file->f_mode;
}
up(&devc->open_sema);
mutex_unlock(&devc->open_mutex);
wake_up(&devc->open_wait);
DEC_USE_COUNT;
DBGR();
@ -3213,7 +3214,7 @@ static int vwsnd_mixer_ioctl(struct inode *ioctl,
DBGEV("(devc=0x%p, cmd=0x%x, arg=0x%lx)\n", devc, cmd, arg);
down(&devc->mix_sema);
mutex_lock(&devc->mix_mutex);
{
if ((cmd & ~nrmask) == MIXER_READ(0))
retval = mixer_read_ioctl(devc, nr, (void __user *) arg);
@ -3222,7 +3223,7 @@ static int vwsnd_mixer_ioctl(struct inode *ioctl,
else
retval = -EINVAL;
}
up(&devc->mix_sema);
mutex_unlock(&devc->mix_mutex);
return retval;
}
@ -3376,9 +3377,9 @@ static int __init attach_vwsnd(struct address_info *hw_config)
/* Initialize as much of *devc as possible */
init_MUTEX(&devc->open_sema);
init_MUTEX(&devc->io_sema);
init_MUTEX(&devc->mix_sema);
mutex_init(&devc->open_mutex);
mutex_init(&devc->io_mutex);
mutex_init(&devc->mix_mutex);
devc->open_mode = 0;
spin_lock_init(&devc->rport.lock);
init_waitqueue_head(&devc->rport.queue);

Просмотреть файл

@ -1918,10 +1918,10 @@ static int ymf_open(struct inode *inode, struct file *file)
if (unit == NULL)
return -ENODEV;
down(&unit->open_sem);
mutex_lock(&unit->open_mutex);
if ((state = ymf_state_alloc(unit)) == NULL) {
up(&unit->open_sem);
mutex_unlock(&unit->open_mutex);
return -ENOMEM;
}
list_add_tail(&state->chain, &unit->states);
@ -1956,7 +1956,7 @@ static int ymf_open(struct inode *inode, struct file *file)
ymfpci_writeb(unit, YDSXGR_TIMERCTRL,
(YDSXGR_TIMERCTRL_TEN|YDSXGR_TIMERCTRL_TIEN));
#endif
up(&unit->open_sem);
mutex_unlock(&unit->open_mutex);
return nonseekable_open(inode, file);
@ -1974,7 +1974,7 @@ out_nodma:
list_del(&state->chain);
kfree(state);
up(&unit->open_sem);
mutex_unlock(&unit->open_mutex);
return err;
}
@ -1987,7 +1987,7 @@ static int ymf_release(struct inode *inode, struct file *file)
ymfpci_writeb(unit, YDSXGR_TIMERCTRL, 0);
#endif
down(&unit->open_sem);
mutex_lock(&unit->open_mutex);
/*
* XXX Solve the case of O_NONBLOCK close - don't deallocate here.
@ -2004,7 +2004,7 @@ static int ymf_release(struct inode *inode, struct file *file)
file->private_data = NULL; /* Can you tell I programmed Solaris */
kfree(state);
up(&unit->open_sem);
mutex_unlock(&unit->open_mutex);
return 0;
}
@ -2532,7 +2532,7 @@ static int __devinit ymf_probe_one(struct pci_dev *pcidev, const struct pci_devi
spin_lock_init(&codec->reg_lock);
spin_lock_init(&codec->voice_lock);
spin_lock_init(&codec->ac97_lock);
init_MUTEX(&codec->open_sem);
mutex_init(&codec->open_mutex);
INIT_LIST_HEAD(&codec->states);
codec->pci = pcidev;

Просмотреть файл

@ -22,6 +22,7 @@
*
*/
#include <linux/config.h>
#include <linux/mutex.h>
/*
* Direct registers
@ -279,7 +280,7 @@ struct ymf_unit {
/* soundcore stuff */
int dev_audio;
struct semaphore open_sem;
struct mutex open_mutex;
struct list_head ymf_devs;
struct list_head states; /* List of states for this unit */