param: simple locking for sysfs-writable charp parameters
[linux-block.git] / arch / um / drivers / hostaudio_kern.c
index ae42695c3597991b338bff62bd19aa22bb194790..0c46e398cd8f313d89a3ff07187916aa6021b93f 100644 (file)
@@ -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"
@@ -186,7 +187,9 @@ static int hostaudio_open(struct inode *inode, struct file *file)
        int ret;
 
 #ifdef DEBUG
+       kparam_block_sysfs_write(dsp);
        printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp);
+       kparam_unblock_sysfs_write(dsp);
 #endif
 
        state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
@@ -198,7 +201,12 @@ static int hostaudio_open(struct inode *inode, struct file *file)
        if (file->f_mode & FMODE_WRITE)
                w = 1;
 
+       kparam_block_sysfs_write(dsp);
+       lock_kernel();
        ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
+       unlock_kernel();
+       kparam_unblock_sysfs_write(dsp);
+
        if (ret < 0) {
                kfree(state);
                return ret;
@@ -254,11 +262,17 @@ static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
        if (file->f_mode & FMODE_WRITE)
                w = 1;
 
+       kparam_block_sysfs_write(mixer);
+       lock_kernel();
        ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
+       unlock_kernel();
+       kparam_unblock_sysfs_write(mixer);
 
        if (ret < 0) {
+               kparam_block_sysfs_write(dsp);
                printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
                       "err = %d\n", dsp, -ret);
+               kparam_unblock_sysfs_write(dsp);
                kfree(state);
                return ret;
        }
@@ -314,8 +328,10 @@ MODULE_LICENSE("GPL");
 
 static int __init hostaudio_init_module(void)
 {
+       __kernel_param_lock();
        printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
               dsp, mixer);
+       __kernel_param_unlock();
 
        module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
        if (module_data.dev_audio < 0) {