Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90dc763f authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Takashi Iwai
Browse files

sound: push BKL into open functions



This moves the lock_kernel() call from soundcore_open
to the individual OSS device drivers, where we can deal
with it one driver at a time if needed, or just kill
off the drivers.

All core components in ALSA already provide
adequate locking in their open()-functions
and do not require the big kernel lock, so
there is no need to add the BKL there.

Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 395c61d1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#include "linux/slab.h"
#include "linux/sound.h"
#include "linux/soundcard.h"
#include "linux/smp_lock.h"
#include "asm/uaccess.h"
#include "init.h"
#include "os.h"
@@ -198,7 +199,10 @@ static int hostaudio_open(struct inode *inode, struct file *file)
	if (file->f_mode & FMODE_WRITE)
		w = 1;

	lock_kernel();
	ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
	unlock_kernel();

	if (ret < 0) {
		kfree(state);
		return ret;
@@ -254,7 +258,9 @@ static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
	if (file->f_mode & FMODE_WRITE)
		w = 1;

	lock_kernel();
	ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
	unlock_kernel();

	if (ret < 0) {
		printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
+17 −9
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
#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>
@@ -807,7 +808,9 @@ au1550_llseek(struct file *file, loff_t offset, int origin)
static int
au1550_open_mixdev(struct inode *inode, struct file *file)
{
	lock_kernel();
	file->private_data = &au1550_state;
	unlock_kernel();
	return 0;
}

@@ -1797,21 +1800,22 @@ au1550_open(struct inode *inode, struct file *file)
#endif

	file->private_data = s;
	lock_kernel();
	/* wait for device to become free */
	mutex_lock(&s->open_mutex);
	while (s->open_mode & file->f_mode) {
		if (file->f_flags & O_NONBLOCK) {
			mutex_unlock(&s->open_mutex);
			return -EBUSY;
		}
		ret = -EBUSY;
		if (file->f_flags & O_NONBLOCK)
			goto out;
		add_wait_queue(&s->open_wait, &wait);
		__set_current_state(TASK_INTERRUPTIBLE);
		mutex_unlock(&s->open_mutex);
		schedule();
		remove_wait_queue(&s->open_wait, &wait);
		set_current_state(TASK_RUNNING);
		ret = -ERESTARTSYS;
		if (signal_pending(current))
			return -ERESTARTSYS;
			goto out2;
		mutex_lock(&s->open_mutex);
	}

@@ -1840,17 +1844,21 @@ au1550_open(struct inode *inode, struct file *file)

	if (file->f_mode & FMODE_READ) {
		if ((ret = prog_dmabuf_adc(s)))
			return ret;
			goto out;
	}
	if (file->f_mode & FMODE_WRITE) {
		if ((ret = prog_dmabuf_dac(s)))
			return ret;
			goto out;
	}

	s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
	mutex_unlock(&s->open_mutex);
	mutex_init(&s->sem);
	return 0;
	ret = 0;
out:
	mutex_unlock(&s->open_mutex);
out2:
	unlock_kernel();
	return ret;
}

static int
+22 −6
Original line number Diff line number Diff line
@@ -323,9 +323,13 @@ static struct {

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

@@ -737,8 +741,11 @@ static int sq_open(struct inode *inode, struct file *file)
{
	int rc;

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

	rc = write_sq_open(file); /* checks the f_mode */
	if (rc)
@@ -781,10 +788,11 @@ static int sq_open(struct inode *inode, struct file *file)
		sound_set_format(AFMT_MU_LAW);
	}
#endif

	unlock_kernel();
	return 0;
 out:
	module_put(dmasound.mach.owner);
	unlock_kernel();
	return rc;
}

@@ -1226,12 +1234,17 @@ static int state_open(struct inode *inode, struct file *file)
{
	char *buffer = state.buf;
	int len = 0;
	int ret;

	lock_kernel();
	ret = -EBUSY;
	if (state.busy)
		return -EBUSY;
		goto out;

	ret = -ENODEV;
	if (!try_module_get(dmasound.mach.owner))
		return -ENODEV;
		goto out;

	state.ptr = 0;
	state.busy = 1;

@@ -1293,7 +1306,10 @@ printk("dmasound: stat buffer used %d bytes\n", len) ;
		printk(KERN_ERR "dmasound_core: stat buffer overflowed!\n");

	state.len = len;
	return 0;
	ret = 0;
out:
	unlock_kernel();
	return ret;
}

static int state_release(struct inode *inode, struct file *file)
+7 −3
Original line number Diff line number Diff line
@@ -756,12 +756,15 @@ static int dev_open(struct inode *inode, struct file *file)
	int minor = iminor(inode);
	int err = 0;

	lock_kernel();
	if (minor == dev.dsp_minor) {
		if ((file->f_mode & FMODE_WRITE &&
		     test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
		    (file->f_mode & FMODE_READ &&
		     test_bit(F_AUDIO_READ_INUSE, &dev.flags)))
			return -EBUSY;
		     test_bit(F_AUDIO_READ_INUSE, &dev.flags))) {
			err = -EBUSY;
			goto out;
		}

		if ((err = dsp_open(file)) >= 0) {
			dev.nresets = 0;
@@ -782,7 +785,8 @@ static int dev_open(struct inode *inode, struct file *file)
		/* nothing */
	} else
		err = -EINVAL;

out:
	unlock_kernel();
	return err;
}

+7 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/sound.h>
#include <linux/smp_lock.h>
#include <linux/soundcard.h>
#include <linux/interrupt.h>
#include <linux/hrtimer.h>
@@ -216,13 +217,17 @@ static int dac_audio_open(struct inode *inode, struct file *file)
{
	if (file->f_mode & FMODE_READ)
		return -ENODEV;
	if (in_use)

	lock_kernel();
	if (in_use) {
		unlock_kernel();
		return -EBUSY;
	}

	in_use = 1;

	dac_audio_start();

	unlock_kernel();
	return 0;
}

Loading