2007-10-16 02:27:34 -06:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 Steve Schmidtke
|
2005-04-16 16:20:36 -06:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
2012-10-07 20:27:32 -06:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/sound.h>
|
|
|
|
#include <linux/soundcard.h>
|
|
|
|
#include <linux/mutex.h>
|
2016-12-24 12:46:01 -07:00
|
|
|
#include <linux/uaccess.h>
|
2012-10-07 20:27:32 -06:00
|
|
|
#include <init.h>
|
|
|
|
#include <os.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
struct hostaudio_state {
|
2007-02-10 02:44:00 -07:00
|
|
|
int fd;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hostmixer_state {
|
2007-02-10 02:44:00 -07:00
|
|
|
int fd;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#define HOSTAUDIO_DEV_DSP "/dev/sound/dsp"
|
|
|
|
#define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer"
|
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
/*
|
|
|
|
* Changed either at boot time or module load time. At boot, this is
|
2007-02-10 02:43:59 -07:00
|
|
|
* single-threaded; at module load, multiple modules would each have
|
|
|
|
* their own copy of these variables.
|
|
|
|
*/
|
|
|
|
static char *dsp = HOSTAUDIO_DEV_DSP;
|
|
|
|
static char *mixer = HOSTAUDIO_DEV_MIXER;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define DSP_HELP \
|
|
|
|
" This is used to specify the host dsp device to the hostaudio driver.\n" \
|
|
|
|
" The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n"
|
|
|
|
|
|
|
|
#define MIXER_HELP \
|
|
|
|
" This is used to specify the host mixer device to the hostaudio driver.\n"\
|
|
|
|
" The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n"
|
|
|
|
|
2010-10-15 15:34:13 -06:00
|
|
|
module_param(dsp, charp, 0644);
|
|
|
|
MODULE_PARM_DESC(dsp, DSP_HELP);
|
|
|
|
module_param(mixer, charp, 0644);
|
|
|
|
MODULE_PARM_DESC(mixer, MIXER_HELP);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifndef MODULE
|
|
|
|
static int set_dsp(char *name, int *add)
|
|
|
|
{
|
|
|
|
dsp = name;
|
2007-10-16 02:27:34 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
__uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
|
|
|
|
|
|
|
|
static int set_mixer(char *name, int *add)
|
|
|
|
{
|
|
|
|
mixer = name;
|
2007-10-16 02:27:34 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
__uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP);
|
|
|
|
#endif
|
|
|
|
|
2010-09-11 10:38:03 -06:00
|
|
|
static DEFINE_MUTEX(hostaudio_mutex);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* /dev/dsp file operations */
|
|
|
|
|
2006-03-31 03:30:15 -07:00
|
|
|
static ssize_t hostaudio_read(struct file *file, char __user *buffer,
|
|
|
|
size_t count, loff_t *ppos)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostaudio_state *state = file->private_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
void *kbuf;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostaudio: read called, count = %d\n", count);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
kbuf = kmalloc(count, GFP_KERNEL);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (kbuf == NULL)
|
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-05-06 15:51:43 -06:00
|
|
|
err = os_read_file(state->fd, kbuf, count);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (err < 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
if (copy_to_user(buffer, kbuf, err))
|
2005-04-16 16:20:36 -06:00
|
|
|
err = -EFAULT;
|
|
|
|
|
2007-02-10 02:44:00 -07:00
|
|
|
out:
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree(kbuf);
|
2007-10-16 02:27:34 -06:00
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-31 03:30:15 -07:00
|
|
|
static ssize_t hostaudio_write(struct file *file, const char __user *buffer,
|
2005-04-16 16:20:36 -06:00
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostaudio_state *state = file->private_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
void *kbuf;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostaudio: write called, count = %d\n", count);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2016-01-02 12:50:51 -07:00
|
|
|
kbuf = memdup_user(buffer, count);
|
|
|
|
if (IS_ERR(kbuf))
|
|
|
|
return PTR_ERR(kbuf);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-05-06 15:51:43 -06:00
|
|
|
err = os_write_file(state->fd, kbuf, count);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (err < 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
|
|
|
*ppos += err;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(kbuf);
|
2007-10-16 02:27:34 -06:00
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
static unsigned int hostaudio_poll(struct file *file,
|
2005-04-16 16:20:36 -06:00
|
|
|
struct poll_table_struct *wait)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
unsigned int mask = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostaudio: poll called (unimplemented)\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
return mask;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-05-07 09:34:28 -06:00
|
|
|
static long hostaudio_ioctl(struct file *file,
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostaudio_state *state = file->private_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long data = 0;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostaudio: ioctl called, cmd = %u\n", cmd);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
switch(cmd){
|
|
|
|
case SNDCTL_DSP_SPEED:
|
|
|
|
case SNDCTL_DSP_STEREO:
|
|
|
|
case SNDCTL_DSP_GETBLKSIZE:
|
|
|
|
case SNDCTL_DSP_CHANNELS:
|
|
|
|
case SNDCTL_DSP_SUBDIVIDE:
|
|
|
|
case SNDCTL_DSP_SETFRAGMENT:
|
2007-10-16 02:27:34 -06:00
|
|
|
if (get_user(data, (int __user *) arg))
|
2008-05-12 15:01:51 -06:00
|
|
|
return -EFAULT;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os_ioctl_generic(state->fd, cmd, (unsigned long) &data);
|
|
|
|
|
|
|
|
switch(cmd){
|
|
|
|
case SNDCTL_DSP_SPEED:
|
|
|
|
case SNDCTL_DSP_STEREO:
|
|
|
|
case SNDCTL_DSP_GETBLKSIZE:
|
|
|
|
case SNDCTL_DSP_CHANNELS:
|
|
|
|
case SNDCTL_DSP_SUBDIVIDE:
|
|
|
|
case SNDCTL_DSP_SETFRAGMENT:
|
2007-10-16 02:27:34 -06:00
|
|
|
if (put_user(data, (int __user *) arg))
|
|
|
|
return -EFAULT;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
return err;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hostaudio_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostaudio_state *state;
|
|
|
|
int r = 0, w = 0;
|
|
|
|
int ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_lock(THIS_MODULE);
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp);
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_unlock(THIS_MODULE);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2007-02-10 02:44:00 -07:00
|
|
|
state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (state == NULL)
|
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
if (file->f_mode & FMODE_READ)
|
|
|
|
r = 1;
|
|
|
|
if (file->f_mode & FMODE_WRITE)
|
|
|
|
w = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_lock(THIS_MODULE);
|
2010-09-11 10:38:03 -06:00
|
|
|
mutex_lock(&hostaudio_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
|
2010-09-11 10:38:03 -06:00
|
|
|
mutex_unlock(&hostaudio_mutex);
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_unlock(THIS_MODULE);
|
2010-07-11 04:16:36 -06:00
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
if (ret < 0) {
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree(state);
|
2007-10-16 02:27:34 -06:00
|
|
|
return ret;
|
2007-02-10 02:44:00 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
state->fd = ret;
|
2007-02-10 02:44:00 -07:00
|
|
|
file->private_data = state;
|
2007-10-16 02:27:34 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hostaudio_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostaudio_state *state = file->private_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostaudio: release called\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2007-02-10 02:44:00 -07:00
|
|
|
os_close_file(state->fd);
|
|
|
|
kfree(state);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* /dev/mixer file operations */
|
|
|
|
|
2010-05-07 09:34:28 -06:00
|
|
|
static long hostmixer_ioctl_mixdev(struct file *file,
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostmixer_state *state = file->private_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostmixer: ioctl called\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
return os_ioctl_generic(state->fd, cmd, arg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostmixer_state *state;
|
|
|
|
int r = 0, w = 0;
|
|
|
|
int ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer);
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2007-02-10 02:44:00 -07:00
|
|
|
state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (state == NULL)
|
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
if (file->f_mode & FMODE_READ)
|
|
|
|
r = 1;
|
|
|
|
if (file->f_mode & FMODE_WRITE)
|
|
|
|
w = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_lock(THIS_MODULE);
|
2010-09-11 10:38:03 -06:00
|
|
|
mutex_lock(&hostaudio_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
|
2010-09-11 10:38:03 -06:00
|
|
|
mutex_unlock(&hostaudio_mutex);
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_unlock(THIS_MODULE);
|
2007-10-16 02:27:34 -06:00
|
|
|
|
|
|
|
if (ret < 0) {
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_lock(THIS_MODULE);
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
|
|
|
|
"err = %d\n", dsp, -ret);
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_unlock(THIS_MODULE);
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree(state);
|
2007-10-16 02:27:34 -06:00
|
|
|
return ret;
|
2007-02-10 02:44:00 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-02-10 02:44:00 -07:00
|
|
|
file->private_data = state;
|
2007-10-16 02:27:34 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hostmixer_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
struct hostmixer_state *state = file->private_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2007-10-16 02:27:34 -06:00
|
|
|
printk(KERN_DEBUG "hostmixer: release called\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
2007-02-10 02:44:00 -07:00
|
|
|
os_close_file(state->fd);
|
|
|
|
kfree(state);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-16 02:27:34 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* kernel module operations */
|
|
|
|
|
2006-09-27 02:50:33 -06:00
|
|
|
static const struct file_operations hostaudio_fops = {
|
2007-02-10 02:44:00 -07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.read = hostaudio_read,
|
|
|
|
.write = hostaudio_write,
|
|
|
|
.poll = hostaudio_poll,
|
2010-05-07 09:34:28 -06:00
|
|
|
.unlocked_ioctl = hostaudio_ioctl,
|
2007-02-10 02:44:00 -07:00
|
|
|
.mmap = NULL,
|
|
|
|
.open = hostaudio_open,
|
|
|
|
.release = hostaudio_release,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2006-09-27 02:50:33 -06:00
|
|
|
static const struct file_operations hostmixer_fops = {
|
2007-02-10 02:44:00 -07:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
2010-05-07 09:34:28 -06:00
|
|
|
.unlocked_ioctl = hostmixer_ioctl_mixdev,
|
2007-02-10 02:44:00 -07:00
|
|
|
.open = hostmixer_open_mixdev,
|
|
|
|
.release = hostmixer_release,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int dev_audio;
|
|
|
|
int dev_mixer;
|
|
|
|
} module_data;
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Steve Schmidtke");
|
|
|
|
MODULE_DESCRIPTION("UML Audio Relay");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static int __init hostaudio_init_module(void)
|
|
|
|
{
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_lock(THIS_MODULE);
|
2007-02-10 02:44:00 -07:00
|
|
|
printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
|
2005-04-16 16:20:36 -06:00
|
|
|
dsp, mixer);
|
module: add per-module param_lock
Add a "param_lock" mutex to each module, and update params.c to use
the correct built-in or module mutex while locking kernel params.
Remove the kparam_block_sysfs_r/w() macros, replace them with direct
calls to kernel_param_[un]lock(module).
The kernel param code currently uses a single mutex to protect
modification of any and all kernel params. While this generally works,
there is one specific problem with it; a module callback function
cannot safely load another module, i.e. with request_module() or even
with indirect calls such as crypto_has_alg(). If the module to be
loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
config file), then the attempt will result in a deadlock between the
first module param callback waiting for modprobe, and modprobe trying to
lock the single kernel param mutex to set the new module's param.
This fixes that by using per-module mutexes, so that each individual module
is protected against concurrent changes in its own kernel params, but is
not blocked by changes to other module params. All built-in modules
continue to use the built-in mutex, since they will always be loaded at
runtime and references (e.g. request_module(), crypto_has_alg()) to them
will never cause load-time param changing.
This also simplifies the interface used by modules to block sysfs access
to their params; while there are currently functions to block and unblock
sysfs param access which are split up by read and write and expect a single
kernel param to be passed, their actual operation is identical and applies
to all params, not just the one passed to them; they simply lock and unlock
the global param mutex. They are replaced with direct calls to
kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
if the module is built-in, it locks the built-in mutex.
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-06-16 14:48:52 -06:00
|
|
|
kernel_param_unlock(THIS_MODULE);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (module_data.dev_audio < 0) {
|
2007-02-10 02:44:00 -07:00
|
|
|
printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
|
2007-10-16 02:27:34 -06:00
|
|
|
if (module_data.dev_mixer < 0) {
|
2007-02-10 02:44:00 -07:00
|
|
|
printk(KERN_ERR "hostmixer: couldn't register mixer "
|
2005-04-16 16:20:36 -06:00
|
|
|
"device!\n");
|
2007-02-10 02:44:00 -07:00
|
|
|
unregister_sound_dsp(module_data.dev_audio);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-02-10 02:44:00 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit hostaudio_cleanup_module (void)
|
|
|
|
{
|
2007-02-10 02:44:00 -07:00
|
|
|
unregister_sound_mixer(module_data.dev_mixer);
|
|
|
|
unregister_sound_dsp(module_data.dev_audio);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(hostaudio_init_module);
|
|
|
|
module_exit(hostaudio_cleanup_module);
|