]> err.no Git - linux-2.6/blobdiff - sound/core/control.c
Merge git://git.infradead.org/~dwmw2/rbtree-2.6
[linux-2.6] / sound / core / control.c
index 1a14338bd51623ad82d2edce18fd53fba1068384..22565c9b9603ea3b43b6794ef7f09b724d338122 100644 (file)
@@ -47,13 +47,12 @@ static LIST_HEAD(snd_control_compat_ioctls);
 
 static int snd_ctl_open(struct inode *inode, struct file *file)
 {
-       int cardnum = SNDRV_MINOR_CARD(iminor(inode));
        unsigned long flags;
        struct snd_card *card;
        struct snd_ctl_file *ctl;
        int err;
 
-       card = snd_cards[cardnum];
+       card = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_CONTROL);
        if (!card) {
                err = -ENODEV;
                goto __error1;
@@ -195,8 +194,10 @@ struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control, unsigned int acce
        snd_assert(control != NULL, return NULL);
        snd_assert(control->count > 0, return NULL);
        kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
-       if (kctl == NULL)
+       if (kctl == NULL) {
+               snd_printk(KERN_ERR "Cannot allocate control instance\n");
                return NULL;
+       }
        *kctl = *control;
        for (idx = 0; idx < kctl->count; idx++)
                kctl->vd[idx].access = access;
@@ -308,26 +309,29 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
 {
        struct snd_ctl_elem_id id;
        unsigned int idx;
+       int err = -EINVAL;
 
-       snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
-       snd_assert(kcontrol->info != NULL, return -EINVAL);
+       if (! kcontrol)
+               return err;
+       snd_assert(card != NULL, goto error);
+       snd_assert(kcontrol->info != NULL, goto error);
        id = kcontrol->id;
        down_write(&card->controls_rwsem);
        if (snd_ctl_find_id(card, &id)) {
                up_write(&card->controls_rwsem);
-               snd_ctl_free_one(kcontrol);
                snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
                                        id.iface,
                                        id.device,
                                        id.subdevice,
                                        id.name,
                                        id.index);
-               return -EBUSY;
+               err = -EBUSY;
+               goto error;
        }
        if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
                up_write(&card->controls_rwsem);
-               snd_ctl_free_one(kcontrol);
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto error;
        }
        list_add_tail(&kcontrol->list, &card->controls);
        card->controls_count += kcontrol->count;
@@ -337,6 +341,10 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
        for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
                snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
        return 0;
+
+ error:
+       snd_ctl_free_one(kcontrol);
+       return err;
 }
 
 /**
@@ -655,7 +663,11 @@ static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl,
 
        if (copy_from_user(&info, _info, sizeof(info)))
                return -EFAULT;
-       result = snd_ctl_elem_info(ctl, &info);
+       snd_power_lock(ctl->card);
+       result = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0);
+       if (result >= 0)
+               result = snd_ctl_elem_info(ctl, &info);
+       snd_power_unlock(ctl->card);
        if (result >= 0)
                if (copy_to_user(_info, &info, sizeof(info)))
                        return -EFAULT;
@@ -705,7 +717,11 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
                kfree(control);
                return -EFAULT;
        }
-       result = snd_ctl_elem_read(card, control);
+       snd_power_lock(card);
+       result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
+       if (result >= 0)
+               result = snd_ctl_elem_read(card, control);
+       snd_power_unlock(card);
        if (result >= 0)
                if (copy_to_user(_control, control, sizeof(*control)))
                        result = -EFAULT;
@@ -755,6 +771,7 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
                                   struct snd_ctl_elem_value __user *_control)
 {
        struct snd_ctl_elem_value *control;
+       struct snd_card *card;
        int result;
 
        control = kmalloc(sizeof(*control), GFP_KERNEL);
@@ -764,7 +781,12 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
                kfree(control);
                return -EFAULT;
        }
-       result = snd_ctl_elem_write(file->card, file, control);
+       card = file->card;
+       snd_power_lock(card);
+       result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
+       if (result >= 0)
+               result = snd_ctl_elem_write(card, file, control);
+       snd_power_unlock(card);
        if (result >= 0)
                if (copy_to_user(_control, control, sizeof(*control)))
                        result = -EFAULT;
@@ -956,17 +978,15 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
        kctl.private_free = snd_ctl_elem_user_free;
        _kctl = snd_ctl_new(&kctl, access);
        if (_kctl == NULL) {
-               kfree(_kctl->private_data);
+               kfree(ue);
                return -ENOMEM;
        }
        _kctl->private_data = ue;
        for (idx = 0; idx < _kctl->count; idx++)
                _kctl->vd[idx].owner = file;
        err = snd_ctl_add(card, _kctl);
-       if (err < 0) {
-               snd_ctl_free_one(_kctl);
+       if (err < 0)
                return err;
-       }
 
        down_write(&card->controls_rwsem);
        card->user_ctl_count++;
@@ -1023,36 +1043,6 @@ static int snd_ctl_subscribe_events(struct snd_ctl_file *file, int __user *ptr)
        return 0;
 }
 
-#ifdef CONFIG_PM
-/*
- * change the power state
- */
-static int snd_ctl_set_power_state(struct snd_card *card, unsigned int power_state)
-{
-       switch (power_state) {
-       case SNDRV_CTL_POWER_D0:
-               if (card->power_state != power_state) {
-                       card->pm_resume(card);
-                       snd_power_change_state(card, power_state);
-               }
-               break;
-       case SNDRV_CTL_POWER_D3hot:
-               if (card->power_state != power_state) {
-                       card->pm_suspend(card, PMSG_SUSPEND);
-                       snd_power_change_state(card, power_state);
-               }
-               break;
-       case SNDRV_CTL_POWER_D1:
-       case SNDRV_CTL_POWER_D2:
-       case SNDRV_CTL_POWER_D3cold:
-               /* not supported yet */
-       default:
-               return -EINVAL;
-       }
-       return 0;
-}
-#endif
-
 static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct snd_ctl_file *ctl;
@@ -1092,19 +1082,7 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg
        case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS:
                return snd_ctl_subscribe_events(ctl, ip);
        case SNDRV_CTL_IOCTL_POWER:
-               if (get_user(err, ip))
-                       return -EFAULT;
-               if (!capable(CAP_SYS_ADMIN))
-                       return -EPERM;
-#ifdef CONFIG_PM
-               if (card->pm_suspend && card->pm_resume) {
-                       snd_power_lock(card);
-                       err = snd_ctl_set_power_state(card, err);
-                       snd_power_unlock(card);
-               } else
-#endif
-                       err = -ENOPROTOOPT;
-               return err;
+               return -ENOPROTOOPT;
        case SNDRV_CTL_IOCTL_POWER_STATE:
 #ifdef CONFIG_PM
                return put_user(card->power_state, ip) ? -EFAULT : 0;
@@ -1302,12 +1280,6 @@ static struct file_operations snd_ctl_f_ops =
        .fasync =       snd_ctl_fasync,
 };
 
-static struct snd_minor snd_ctl_reg =
-{
-       .comment =      "ctl",
-       .f_ops =        &snd_ctl_f_ops,
-};
-
 /*
  * registration of the control device
  */
@@ -1321,8 +1293,8 @@ static int snd_ctl_dev_register(struct snd_device *device)
        cardnum = card->number;
        snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO);
        sprintf(name, "controlC%i", cardnum);
-       if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL,
-                                       card, 0, &snd_ctl_reg, name)) < 0)
+       if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,
+                                      &snd_ctl_f_ops, card, name)) < 0)
                return err;
        return 0;
 }
@@ -1374,7 +1346,8 @@ static int snd_ctl_dev_unregister(struct snd_device *device)
        snd_assert(card != NULL, return -ENXIO);
        cardnum = card->number;
        snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO);
-       if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, card, 0)) < 0)
+       if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL,
+                                        card, -1)) < 0)
                return err;
        return snd_ctl_dev_free(device);
 }