vserver 1.9.3
[linux-2.6.git] / sound / core / control.c
index c39afa6..9b000f7 100644 (file)
@@ -22,6 +22,7 @@
 #include <sound/driver.h>
 #include <linux/threads.h>
 #include <linux/interrupt.h>
+#include <linux/smp_lock.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/time.h>
@@ -62,7 +63,7 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
                err = -EFAULT;
                goto __error2;
        }
-       ctl = snd_magic_kcalloc(snd_ctl_file_t, 0, GFP_KERNEL);
+       ctl = kcalloc(1, sizeof(*ctl), GFP_KERNEL);
        if (ctl == NULL) {
                err = -ENOMEM;
                goto __error;
@@ -108,7 +109,7 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
        snd_kcontrol_t *control;
        unsigned int idx;
 
-       ctl = snd_magic_cast(snd_ctl_file_t, file->private_data, return -ENXIO);
+       ctl = file->private_data;
        fasync_helper(-1, file, 0, &ctl->fasync);
        file->private_data = NULL;
        card = ctl->card;
@@ -124,7 +125,7 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
        }
        up_write(&card->controls_rwsem);
        snd_ctl_empty_read_queue(ctl);
-       snd_magic_kfree(ctl);
+       kfree(ctl);
        module_put(card->module);
        snd_card_file_remove(card, file);
        return 0;
@@ -155,7 +156,7 @@ void snd_ctl_notify(snd_card_t *card, unsigned int mask, snd_ctl_elem_id_t *id)
                                goto _found;
                        }
                }
-               ev = snd_kcalloc(sizeof(*ev), GFP_ATOMIC);
+               ev = kcalloc(1, sizeof(*ev), GFP_ATOMIC);
                if (ev) {
                        ev->id = *id;
                        ev->mask = mask;
@@ -188,9 +189,7 @@ snd_kcontrol_t *snd_ctl_new(snd_kcontrol_t * control, unsigned int access)
        
        snd_runtime_check(control != NULL, return NULL);
        snd_runtime_check(control->count > 0, return NULL);
-       kctl = (snd_kcontrol_t *)snd_magic_kcalloc(snd_kcontrol_t,
-                                                  sizeof(snd_kcontrol_volatile_t) * control->count,
-                                                  GFP_KERNEL);
+       kctl = kcalloc(1, sizeof(*kctl) + sizeof(snd_kcontrol_volatile_t) * control->count, GFP_KERNEL);
        if (kctl == NULL)
                return NULL;
        *kctl = *control;
@@ -249,7 +248,7 @@ void snd_ctl_free_one(snd_kcontrol_t * kcontrol)
        if (kcontrol) {
                if (kcontrol->private_free)
                        kcontrol->private_free(kcontrol);
-               snd_magic_kfree(kcontrol);
+               kfree(kcontrol);
        }
 }
 
@@ -927,7 +926,7 @@ static int snd_ctl_elem_add(snd_ctl_file_t *file, snd_ctl_elem_info_t __user *_i
        if (!(info.access & SNDRV_CTL_ELEM_ACCESS_DINDIRECT))
                for (idx = 0; idx < 4 && info.dimen.d[idx]; idx++)
                        dimen_size += sizeof(unsigned short);
-       ue = snd_kcalloc(sizeof(struct user_element) + dimen_size + private_size + extra_size, GFP_KERNEL);
+       ue = kcalloc(1, sizeof(struct user_element) + dimen_size + private_size + extra_size, GFP_KERNEL);
        if (ue == NULL)
                return -ENOMEM;
        ue->type = info.type;
@@ -1022,8 +1021,8 @@ static int snd_ctl_set_power_state(snd_card_t *card, unsigned int power_state)
 }
 #endif
 
-static insnd_ctl_ioctl(struct inode *inode, struct file *file,
-                        unsigned int cmd, unsigned long arg)
+static inline int _snd_ctl_ioctl(struct inode *inode, struct file *file,
+                                unsigned int cmd, unsigned long arg)
 {
        snd_ctl_file_t *ctl;
        snd_card_t *card;
@@ -1033,7 +1032,7 @@ static int snd_ctl_ioctl(struct inode *inode, struct file *file,
        int __user *ip = argp;
        int err;
 
-       ctl = snd_magic_cast(snd_ctl_file_t, file->private_data, return -ENXIO);
+       ctl = file->private_data;
        card = ctl->card;
        snd_assert(card != NULL, return -ENXIO);
        switch (cmd) {
@@ -1096,13 +1095,24 @@ static int snd_ctl_ioctl(struct inode *inode, struct file *file,
        return -ENOTTY;
 }
 
+/* FIXME: need to unlock BKL to allow preemption */
+static int snd_ctl_ioctl(struct inode *inode, struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       int err;
+       unlock_kernel();
+       err = _snd_ctl_ioctl(inode, file, cmd, arg);
+       lock_kernel();
+       return err;
+}
+
 static ssize_t snd_ctl_read(struct file *file, char __user *buffer, size_t count, loff_t * offset)
 {
        snd_ctl_file_t *ctl;
        int err = 0;
        ssize_t result = 0;
 
-       ctl = snd_magic_cast(snd_ctl_file_t, file->private_data, return -ENXIO);
+       ctl = file->private_data;
        snd_assert(ctl != NULL && ctl->card != NULL, return -ENXIO);
        if (!ctl->subscribed)
                return -EBADFD;
@@ -1116,7 +1126,7 @@ static ssize_t snd_ctl_read(struct file *file, char __user *buffer, size_t count
                        wait_queue_t wait;
                        if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
                                err = -EAGAIN;
-                               goto __end;
+                               goto __end_lock;
                        }
                        init_waitqueue_entry(&wait, current);
                        add_wait_queue(&ctl->change_sleep, &wait);
@@ -1137,16 +1147,16 @@ static ssize_t snd_ctl_read(struct file *file, char __user *buffer, size_t count
                kfree(kev);
                if (copy_to_user(buffer, &ev, sizeof(snd_ctl_event_t))) {
                        err = -EFAULT;
-                       goto out;
+                       goto __end;
                }
                spin_lock_irq(&ctl->read_lock);
                buffer += sizeof(snd_ctl_event_t);
                count -= sizeof(snd_ctl_event_t);
                result += sizeof(snd_ctl_event_t);
        }
-__end:
+      __end_lock:
        spin_unlock_irq(&ctl->read_lock);
-out:
+      __end:
        return result > 0 ? result : err;
 }
 
@@ -1155,7 +1165,7 @@ static unsigned int snd_ctl_poll(struct file *file, poll_table * wait)
        unsigned int mask;
        snd_ctl_file_t *ctl;
 
-       ctl = snd_magic_cast(snd_ctl_file_t, file->private_data, return 0);
+       ctl = file->private_data;
        if (!ctl->subscribed)
                return 0;
        poll_wait(file, &ctl->change_sleep, wait);
@@ -1175,8 +1185,7 @@ int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn)
 {
        snd_kctl_ioctl_t *pn;
 
-       pn = (snd_kctl_ioctl_t *)
-               snd_kcalloc(sizeof(snd_kctl_ioctl_t), GFP_KERNEL);
+       pn = kcalloc(1, sizeof(snd_kctl_ioctl_t), GFP_KERNEL);
        if (pn == NULL)
                return -ENOMEM;
        pn->fioctl = fcn;
@@ -1214,7 +1223,7 @@ static int snd_ctl_fasync(int fd, struct file * file, int on)
 {
        snd_ctl_file_t *ctl;
        int err;
-       ctl = snd_magic_cast(snd_ctl_file_t, file->private_data, return -ENXIO);
+       ctl = file->private_data;
        err = fasync_helper(fd, file, on, &ctl->fasync);
        if (err < 0)
                return err;