Skip to content

Commit

Permalink
sound: autoconvert trivial BKL users to private mutex
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
arndb authored and tiwai committed Sep 14, 2010
1 parent 7b6c3a3 commit 645ef9e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 93 deletions.
30 changes: 15 additions & 15 deletions sound/oss/au1550_ac97.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <linux/sound.h>
#include <linux/slab.h>
#include <linux/soundcard.h>
#include <linux/smp_lock.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
Expand Down Expand Up @@ -77,6 +76,7 @@
/* Boot options
* 0 = no VRA, 1 = use VRA if codec supports it
*/
static DEFINE_MUTEX(au1550_ac97_mutex);
static int vra = 1;
module_param(vra, bool, 0);
MODULE_PARM_DESC(vra, "if 1 use VRA if codec supports it");
Expand Down Expand Up @@ -798,9 +798,9 @@ au1550_llseek(struct file *file, loff_t offset, int origin)
static int
au1550_open_mixdev(struct inode *inode, struct file *file)
{
lock_kernel();
mutex_lock(&au1550_ac97_mutex);
file->private_data = &au1550_state;
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);
return 0;
}

Expand All @@ -824,9 +824,9 @@ au1550_ioctl_mixdev(struct file *file, unsigned int cmd, unsigned long arg)
struct ac97_codec *codec = s->codec;
int ret;

lock_kernel();
mutex_lock(&au1550_ac97_mutex);
ret = mixdev_ioctl(codec, cmd, arg);
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);

return ret;
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ au1550_mmap(struct file *file, struct vm_area_struct *vma)
unsigned long size;
int ret = 0;

lock_kernel();
mutex_lock(&au1550_ac97_mutex);
mutex_lock(&s->sem);
if (vma->vm_flags & VM_WRITE)
db = &s->dma_dac;
Expand Down Expand Up @@ -1283,7 +1283,7 @@ au1550_mmap(struct file *file, struct vm_area_struct *vma)
db->mapped = 1;
out:
mutex_unlock(&s->sem);
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);
return ret;
}

Expand Down Expand Up @@ -1781,9 +1781,9 @@ au1550_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret;

lock_kernel();
mutex_lock(&au1550_ac97_mutex);
ret = au1550_ioctl(file, cmd, arg);
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);

return ret;
}
Expand All @@ -1804,7 +1804,7 @@ au1550_open(struct inode *inode, struct file *file)
#endif

file->private_data = s;
lock_kernel();
mutex_lock(&au1550_ac97_mutex);
/* wait for device to become free */
mutex_lock(&s->open_mutex);
while (s->open_mode & file->f_mode) {
Expand Down Expand Up @@ -1861,7 +1861,7 @@ au1550_open(struct inode *inode, struct file *file)
out:
mutex_unlock(&s->open_mutex);
out2:
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);
return ret;
}

Expand All @@ -1870,12 +1870,12 @@ au1550_release(struct inode *inode, struct file *file)
{
struct au1550_state *s = file->private_data;

lock_kernel();
mutex_lock(&au1550_ac97_mutex);

if (file->f_mode & FMODE_WRITE) {
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);
drain_dac(s, file->f_flags & O_NONBLOCK);
lock_kernel();
mutex_lock(&au1550_ac97_mutex);
}

mutex_lock(&s->open_mutex);
Expand All @@ -1892,7 +1892,7 @@ au1550_release(struct inode *inode, struct file *file)
s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
mutex_unlock(&s->open_mutex);
wake_up(&s->open_wait);
unlock_kernel();
mutex_unlock(&au1550_ac97_mutex);
return 0;
}

Expand Down
41 changes: 21 additions & 20 deletions sound/oss/dmasound/dmasound_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
#include <linux/init.h>
#include <linux/soundcard.h>
#include <linux/poll.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>

#include <asm/uaccess.h>

Expand All @@ -194,6 +194,7 @@
* Declarations
*/

static DEFINE_MUTEX(dmasound_core_mutex);
int dmasound_catchRadius = 0;
module_param(dmasound_catchRadius, int, 0);

Expand Down Expand Up @@ -323,22 +324,22 @@ static struct {

static int mixer_open(struct inode *inode, struct file *file)
{
lock_kernel();
mutex_lock(&dmasound_core_mutex);
if (!try_module_get(dmasound.mach.owner)) {
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return -ENODEV;
}
mixer.busy = 1;
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return 0;
}

static int mixer_release(struct inode *inode, struct file *file)
{
lock_kernel();
mutex_lock(&dmasound_core_mutex);
mixer.busy = 0;
module_put(dmasound.mach.owner);
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return 0;
}

Expand Down Expand Up @@ -370,9 +371,9 @@ static long mixer_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
{
int ret;

lock_kernel();
mutex_lock(&dmasound_core_mutex);
ret = mixer_ioctl(file, cmd, arg);
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);

return ret;
}
Expand Down Expand Up @@ -752,9 +753,9 @@ static int sq_open(struct inode *inode, struct file *file)
{
int rc;

lock_kernel();
mutex_lock(&dmasound_core_mutex);
if (!try_module_get(dmasound.mach.owner)) {
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return -ENODEV;
}

Expand Down Expand Up @@ -799,11 +800,11 @@ static int sq_open(struct inode *inode, struct file *file)
sound_set_format(AFMT_MU_LAW);
}
#endif
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return 0;
out:
module_put(dmasound.mach.owner);
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return rc;
}

Expand Down Expand Up @@ -869,7 +870,7 @@ static int sq_release(struct inode *inode, struct file *file)
{
int rc = 0;

lock_kernel();
mutex_lock(&dmasound_core_mutex);

if (file->f_mode & FMODE_WRITE) {
if (write_sq.busy)
Expand Down Expand Up @@ -900,7 +901,7 @@ static int sq_release(struct inode *inode, struct file *file)
write_sq_wake_up(file); /* checks f_mode */
#endif /* blocking open() */

unlock_kernel();
mutex_unlock(&dmasound_core_mutex);

return rc;
}
Expand Down Expand Up @@ -1141,9 +1142,9 @@ static long sq_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
{
int ret;

lock_kernel();
mutex_lock(&dmasound_core_mutex);
ret = sq_ioctl(file, cmd, arg);
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);

return ret;
}
Expand Down Expand Up @@ -1257,7 +1258,7 @@ static int state_open(struct inode *inode, struct file *file)
int len = 0;
int ret;

lock_kernel();
mutex_lock(&dmasound_core_mutex);
ret = -EBUSY;
if (state.busy)
goto out;
Expand Down Expand Up @@ -1329,16 +1330,16 @@ printk("dmasound: stat buffer used %d bytes\n", len) ;
state.len = len;
ret = 0;
out:
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return ret;
}

static int state_release(struct inode *inode, struct file *file)
{
lock_kernel();
mutex_lock(&dmasound_core_mutex);
state.busy = 0;
module_put(dmasound.mach.owner);
unlock_kernel();
mutex_unlock(&dmasound_core_mutex);
return 0;
}

Expand Down
15 changes: 8 additions & 7 deletions sound/oss/msnd_pinnacle.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/gfp.h>
#include <asm/irq.h>
#include <asm/io.h>
Expand Down Expand Up @@ -79,6 +79,7 @@
dev.rec_sample_rate / \
dev.rec_channels)

static DEFINE_MUTEX(msnd_pinnacle_mutex);
static multisound_dev_t dev;

#ifndef HAVE_DSPCODEH
Expand Down Expand Up @@ -651,12 +652,12 @@ static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

ret = -EINVAL;

lock_kernel();
mutex_lock(&msnd_pinnacle_mutex);
if (minor == dev.dsp_minor)
ret = dsp_ioctl(file, cmd, arg);
else if (minor == dev.mixer_minor)
ret = mixer_ioctl(cmd, arg);
unlock_kernel();
mutex_unlock(&msnd_pinnacle_mutex);

return ret;
}
Expand Down Expand Up @@ -761,7 +762,7 @@ static int dev_open(struct inode *inode, struct file *file)
int minor = iminor(inode);
int err = 0;

lock_kernel();
mutex_lock(&msnd_pinnacle_mutex);
if (minor == dev.dsp_minor) {
if ((file->f_mode & FMODE_WRITE &&
test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
Expand Down Expand Up @@ -791,7 +792,7 @@ static int dev_open(struct inode *inode, struct file *file)
} else
err = -EINVAL;
out:
unlock_kernel();
mutex_unlock(&msnd_pinnacle_mutex);
return err;
}

Expand All @@ -800,14 +801,14 @@ static int dev_release(struct inode *inode, struct file *file)
int minor = iminor(inode);
int err = 0;

lock_kernel();
mutex_lock(&msnd_pinnacle_mutex);
if (minor == dev.dsp_minor)
err = dsp_release(file);
else if (minor == dev.mixer_minor) {
/* nothing */
} else
err = -EINVAL;
unlock_kernel();
mutex_unlock(&msnd_pinnacle_mutex);
return err;
}

Expand Down
13 changes: 7 additions & 6 deletions sound/oss/sh_dac_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/sound.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <linux/soundcard.h>
#include <linux/interrupt.h>
#include <linux/hrtimer.h>
Expand All @@ -34,6 +34,7 @@

#define BUFFER_SIZE 48000

static DEFINE_MUTEX(sh_dac_audio_mutex);
static int rate;
static int empty;
static char *data_buffer, *buffer_begin, *buffer_end;
Expand Down Expand Up @@ -163,9 +164,9 @@ static long dac_audio_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
{
int ret;

lock_kernel();
mutex_lock(&sh_dac_audio_mutex);
ret = dac_audio_ioctl(file, cmd, arg);
unlock_kernel();
mutex_unlock(&sh_dac_audio_mutex);

return ret;
}
Expand Down Expand Up @@ -229,16 +230,16 @@ static int dac_audio_open(struct inode *inode, struct file *file)
if (file->f_mode & FMODE_READ)
return -ENODEV;

lock_kernel();
mutex_lock(&sh_dac_audio_mutex);
if (in_use) {
unlock_kernel();
mutex_unlock(&sh_dac_audio_mutex);
return -EBUSY;
}

in_use = 1;

dac_audio_start();
unlock_kernel();
mutex_unlock(&sh_dac_audio_mutex);
return 0;
}

Expand Down
Loading

0 comments on commit 645ef9e

Please sign in to comment.