Merge remote branch 'alsa/fixes' into fix/hda
[safe/jmp/linux-2.6] / sound / core / control_compat.c
index a529b62..368dc9c 100644 (file)
@@ -107,7 +107,13 @@ static int snd_ctl_elem_info_compat(struct snd_ctl_file *ctl,
         */
        if (get_user(data->value.enumerated.item, &data32->value.enumerated.item))
                goto error;
-       err = snd_ctl_elem_info(ctl, data);
+
+       snd_power_lock(ctl->card);
+       err = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0);
+       if (err >= 0)
+               err = snd_ctl_elem_info(ctl, data);
+       snd_power_unlock(ctl->card);
+
        if (err < 0)
                goto error;
        /* restore info to 32bit */
@@ -213,7 +219,8 @@ static int copy_ctl_value_from_user(struct snd_card *card,
                                    struct snd_ctl_elem_value32 __user *data32,
                                    int *typep, int *countp)
 {
-       int i, type, count, size;
+       int i, type, size;
+       int uninitialized_var(count);
        unsigned int indirect;
 
        if (copy_from_user(&data->id, &data32->id, sizeof(data->id)))
@@ -286,9 +293,14 @@ static int snd_ctl_elem_read_user_compat(struct snd_card *card,
 
        if ((err = copy_ctl_value_from_user(card, data, data32, &type, &count)) < 0)
                goto error;
-       if ((err = snd_ctl_elem_read(card, data)) < 0)
-               goto error;
-       err = copy_ctl_value_to_user(data32, data, type, count);
+
+       snd_power_lock(card);
+       err = snd_power_wait(card, SNDRV_CTL_POWER_D0);
+       if (err >= 0)
+               err = snd_ctl_elem_read(card, data);
+       snd_power_unlock(card);
+       if (err >= 0)
+               err = copy_ctl_value_to_user(data32, data, type, count);
  error:
        kfree(data);
        return err;
@@ -298,17 +310,23 @@ static int snd_ctl_elem_write_user_compat(struct snd_ctl_file *file,
                                          struct snd_ctl_elem_value32 __user *data32)
 {
        struct snd_ctl_elem_value *data;
+       struct snd_card *card = file->card;
        int err, type, count;
 
        data = kzalloc(sizeof(*data), GFP_KERNEL);
        if (data == NULL)
                return -ENOMEM;
 
-       if ((err = copy_ctl_value_from_user(file->card, data, data32, &type, &count)) < 0)
-               goto error;
-       if ((err = snd_ctl_elem_write(file->card, file, data)) < 0)
+       if ((err = copy_ctl_value_from_user(card, data, data32, &type, &count)) < 0)
                goto error;
-       err = copy_ctl_value_to_user(data32, data, type, count);
+
+       snd_power_lock(card);
+       err = snd_power_wait(card, SNDRV_CTL_POWER_D0);
+       if (err >= 0)
+               err = snd_ctl_elem_write(card, file, data);
+       snd_power_unlock(card);
+       if (err >= 0)
+               err = copy_ctl_value_to_user(data32, data, type, count);
  error:
        kfree(data);
        return err;
@@ -375,12 +393,13 @@ enum {
 static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct snd_ctl_file *ctl;
-       struct list_head *list;
+       struct snd_kctl_ioctl *p;
        void __user *argp = compat_ptr(arg);
        int err;
 
        ctl = file->private_data;
-       snd_assert(ctl && ctl->card, return -ENXIO);
+       if (snd_BUG_ON(!ctl || !ctl->card))
+               return -ENXIO;
 
        switch (cmd) {
        case SNDRV_CTL_IOCTL_PVERSION:
@@ -390,6 +409,10 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, uns
        case SNDRV_CTL_IOCTL_POWER_STATE:
        case SNDRV_CTL_IOCTL_ELEM_LOCK:
        case SNDRV_CTL_IOCTL_ELEM_UNLOCK:
+       case SNDRV_CTL_IOCTL_ELEM_REMOVE:
+       case SNDRV_CTL_IOCTL_TLV_READ:
+       case SNDRV_CTL_IOCTL_TLV_WRITE:
+       case SNDRV_CTL_IOCTL_TLV_COMMAND:
                return snd_ctl_ioctl(file, cmd, (unsigned long)argp);
        case SNDRV_CTL_IOCTL_ELEM_LIST32:
                return snd_ctl_elem_list_compat(ctl->card, argp);
@@ -406,8 +429,7 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, uns
        }
 
        down_read(&snd_ioctl_rwsem);
-       list_for_each(list, &snd_control_compat_ioctls) {
-               struct snd_kctl_ioctl *p = list_entry(list, struct snd_kctl_ioctl, list);
+       list_for_each_entry(p, &snd_control_compat_ioctls, list) {
                if (p->fioctl) {
                        err = p->fioctl(ctl->card, ctl, cmd, arg);
                        if (err != -ENOIOCTLCMD) {