]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
ALSA: Fix limit of 8 PCM devices in SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE
authorPawel MOLL <pawel.moll@st.com>
Wed, 30 Jul 2008 11:46:40 +0000 (12:46 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 1 Aug 2008 11:37:15 +0000 (13:37 +0200)
When compiled with CONFIG_SND_DYNAMIC_MINORS the ALSA core is fine
to have more than 8 PCM devices per card, except one place - the
SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE ioctl, which will not enumerate
devices > 7. This patch fixes the issue, changing the devices list
organisation.

Instead of adding new device to the tail, the list is now kept always
ordered (by card number, then device number). Thus, during enumeration,
it is easy to discover the fact that there is no more given card's
devices.

Additionally the device field of struct snd_pcm had to be changed to int,
as its "unsignednity" caused a lot of problems when comparing it to
potentially negative signed values. (-1 is 0xffffffff or even more then ;-)

Signed-off-by: Pawel Moll <pawel.moll@st.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/sound/minors.h
include/sound/pcm.h
sound/core/pcm.c
sound/core/sound.c

index 46bcd2023ed8e7d7e55f305d100168108414b8b4..a81798ab73edc1bcdeb8e39ff9068febd2647b51 100644 (file)
@@ -21,6 +21,8 @@
  *
  */
 
+#define SNDRV_OS_MINORS                        256
+
 #define SNDRV_MINOR_DEVICES            32
 #define SNDRV_MINOR_CARD(minor)                ((minor) >> 5)
 #define SNDRV_MINOR_DEVICE(minor)      ((minor) & 0x001f)
index 51d58ccda2d82d7158cbca22fb338bafa393c0e0..5dd8ea4a8c4b1a9decf0796b6ec1a2ce468b9eee 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <sound/asound.h>
 #include <sound/memalloc.h>
+#include <sound/minors.h>
 #include <linux/poll.h>
 #include <linux/mm.h>
 #include <linux/bitops.h>
@@ -84,7 +85,11 @@ struct snd_pcm_ops {
  *
  */
 
-#define SNDRV_PCM_DEVICES              8
+#if defined(CONFIG_SND_DYNAMIC_MINORS)
+#define SNDRV_PCM_DEVICES      (SNDRV_OS_MINORS-2)
+#else
+#define SNDRV_PCM_DEVICES      8
+#endif
 
 #define SNDRV_PCM_IOCTL1_FALSE         ((void *)0)
 #define SNDRV_PCM_IOCTL1_TRUE          ((void *)1)
@@ -416,7 +421,7 @@ struct snd_pcm_str {
 struct snd_pcm {
        struct snd_card *card;
        struct list_head list;
-       unsigned int device;    /* device number */
+       int device; /* device number */
        unsigned int info_flags;
        unsigned short dev_class;
        unsigned short dev_subclass;
index ece25c718e95e8f78c5a71b01df6e01e80519908..517388b2eba9eb8ba813441ffad9fa785c98b39d 100644 (file)
@@ -42,7 +42,7 @@ static int snd_pcm_dev_free(struct snd_device *device);
 static int snd_pcm_dev_register(struct snd_device *device);
 static int snd_pcm_dev_disconnect(struct snd_device *device);
 
-static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device)
+static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
 {
        struct snd_pcm *pcm;
 
@@ -53,6 +53,37 @@ static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device)
        return NULL;
 }
 
+static int snd_pcm_next(struct snd_card *card, int device)
+{
+       struct snd_pcm *pcm;
+
+       list_for_each_entry(pcm, &snd_pcm_devices, list) {
+               if (pcm->card == card && pcm->device > device)
+                       return pcm->device;
+               else if (pcm->card->number > card->number)
+                       return -1;
+       }
+       return -1;
+}
+
+static int snd_pcm_add(struct snd_pcm *newpcm)
+{
+       struct snd_pcm *pcm;
+
+       list_for_each_entry(pcm, &snd_pcm_devices, list) {
+               if (pcm->card == newpcm->card && pcm->device == newpcm->device)
+                       return -EBUSY;
+               if (pcm->card->number > newpcm->card->number ||
+                               (pcm->card == newpcm->card &&
+                               pcm->device > newpcm->device)) {
+                       list_add(&newpcm->list, pcm->list.prev);
+                       return 0;
+               }
+       }
+       list_add_tail(&newpcm->list, &snd_pcm_devices);
+       return 0;
+}
+
 static int snd_pcm_control_ioctl(struct snd_card *card,
                                 struct snd_ctl_file *control,
                                 unsigned int cmd, unsigned long arg)
@@ -65,14 +96,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card,
                        if (get_user(device, (int __user *)arg))
                                return -EFAULT;
                        mutex_lock(&register_mutex);
-                       device = device < 0 ? 0 : device + 1;
-                       while (device < SNDRV_PCM_DEVICES) {
-                               if (snd_pcm_search(card, device))
-                                       break;
-                               device++;
-                       }
-                       if (device == SNDRV_PCM_DEVICES)
-                               device = -1;
+                       device = snd_pcm_next(card, device);
                        mutex_unlock(&register_mutex);
                        if (put_user(device, (int __user *)arg))
                                return -EFAULT;
@@ -98,7 +122,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card,
                        if (get_user(subdevice, &info->subdevice))
                                return -EFAULT;
                        mutex_lock(&register_mutex);
-                       pcm = snd_pcm_search(card, device);
+                       pcm = snd_pcm_get(card, device);
                        if (pcm == NULL) {
                                err = -ENXIO;
                                goto _error;
@@ -931,11 +955,11 @@ static int snd_pcm_dev_register(struct snd_device *device)
 
        snd_assert(pcm != NULL && device != NULL, return -ENXIO);
        mutex_lock(&register_mutex);
-       if (snd_pcm_search(pcm->card, pcm->device)) {
+       err = snd_pcm_add(pcm);
+       if (err) {
                mutex_unlock(&register_mutex);
-               return -EBUSY;
+               return err;
        }
-       list_add_tail(&pcm->list, &snd_pcm_devices);
        for (cidx = 0; cidx < 2; cidx++) {
                int devtype = -1;
                if (pcm->streams[cidx].substream == NULL)
index 1003ae375d478429e128bb7138b751486f069178..838dd9ee957ce3e3549600cfca55e9400ee5b360 100644 (file)
@@ -34,8 +34,6 @@
 #include <linux/kmod.h>
 #include <linux/mutex.h>
 
-#define SNDRV_OS_MINORS 256
-
 static int major = CONFIG_SND_MAJOR;
 int snd_major;
 EXPORT_SYMBOL(snd_major);