Commit 94239690 authored by Pawel MOLL's avatar Pawel MOLL Committed by Jaroslav Kysela

ALSA: Fix limit of 8 PCM devices in SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE

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. The same limit was present in OSS emulation code. It has
been fixed as well.

Additionally the device field of struct snd_pcm is now int, instead of
unsigned int, as there is no obvious reason for keeping it unsigned.
This caused a lot of problems with comparing this value with other
(almost always signed) variables. There is just one more place where
device number is unsigned - in struct snd_pcm_info, which should be
also sorted out in future.
Signed-off-by: default avatarPawel MOLL <pawel.moll@st.com>
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 815ecf8d
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
* *
*/ */
#define SNDRV_OS_MINORS 256
#define SNDRV_MINOR_DEVICES 32 #define SNDRV_MINOR_DEVICES 32
#define SNDRV_MINOR_CARD(minor) ((minor) >> 5) #define SNDRV_MINOR_CARD(minor) ((minor) >> 5)
#define SNDRV_MINOR_DEVICE(minor) ((minor) & 0x001f) #define SNDRV_MINOR_DEVICE(minor) ((minor) & 0x001f)
......
...@@ -84,8 +84,6 @@ struct snd_pcm_ops { ...@@ -84,8 +84,6 @@ struct snd_pcm_ops {
* *
*/ */
#define SNDRV_PCM_DEVICES 8
#define SNDRV_PCM_IOCTL1_FALSE ((void *)0) #define SNDRV_PCM_IOCTL1_FALSE ((void *)0)
#define SNDRV_PCM_IOCTL1_TRUE ((void *)1) #define SNDRV_PCM_IOCTL1_TRUE ((void *)1)
...@@ -416,7 +414,7 @@ struct snd_pcm_str { ...@@ -416,7 +414,7 @@ struct snd_pcm_str {
struct snd_pcm { struct snd_pcm {
struct snd_card *card; struct snd_card *card;
struct list_head list; struct list_head list;
unsigned int device; /* device number */ int device; /* device number */
unsigned int info_flags; unsigned int info_flags;
unsigned short dev_class; unsigned short dev_class;
unsigned short dev_subclass; unsigned short dev_subclass;
......
...@@ -2947,7 +2947,7 @@ static void register_oss_dsp(struct snd_pcm *pcm, int index) ...@@ -2947,7 +2947,7 @@ static void register_oss_dsp(struct snd_pcm *pcm, int index)
static int snd_pcm_oss_register_minor(struct snd_pcm *pcm) static int snd_pcm_oss_register_minor(struct snd_pcm *pcm)
{ {
pcm->oss.reg = 0; pcm->oss.reg = 0;
if (dsp_map[pcm->card->number] == (int)pcm->device) { if (dsp_map[pcm->card->number] == pcm->device) {
char name[128]; char name[128];
int duplex; int duplex;
register_oss_dsp(pcm, 0); register_oss_dsp(pcm, 0);
...@@ -2963,7 +2963,7 @@ static int snd_pcm_oss_register_minor(struct snd_pcm *pcm) ...@@ -2963,7 +2963,7 @@ static int snd_pcm_oss_register_minor(struct snd_pcm *pcm)
pcm->oss.reg++; pcm->oss.reg++;
pcm->oss.reg_mask |= 1; pcm->oss.reg_mask |= 1;
} }
if (adsp_map[pcm->card->number] == (int)pcm->device) { if (adsp_map[pcm->card->number] == pcm->device) {
register_oss_dsp(pcm, 1); register_oss_dsp(pcm, 1);
pcm->oss.reg++; pcm->oss.reg++;
pcm->oss.reg_mask |= 2; pcm->oss.reg_mask |= 2;
...@@ -2988,7 +2988,7 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm) ...@@ -2988,7 +2988,7 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)
snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM, snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
pcm->card, 1); pcm->card, 1);
} }
if (dsp_map[pcm->card->number] == (int)pcm->device) { if (dsp_map[pcm->card->number] == pcm->device) {
#ifdef SNDRV_OSS_INFO_DEV_AUDIO #ifdef SNDRV_OSS_INFO_DEV_AUDIO
snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_AUDIO, pcm->card->number); snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_AUDIO, pcm->card->number);
#endif #endif
...@@ -3019,12 +3019,12 @@ static int __init alsa_pcm_oss_init(void) ...@@ -3019,12 +3019,12 @@ static int __init alsa_pcm_oss_init(void)
/* check device map table */ /* check device map table */
for (i = 0; i < SNDRV_CARDS; i++) { for (i = 0; i < SNDRV_CARDS; i++) {
if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) { if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_OS_MINORS) {
snd_printk(KERN_ERR "invalid dsp_map[%d] = %d\n", snd_printk(KERN_ERR "invalid dsp_map[%d] = %d\n",
i, dsp_map[i]); i, dsp_map[i]);
dsp_map[i] = 0; dsp_map[i] = 0;
} }
if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_PCM_DEVICES) { if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_OS_MINORS) {
snd_printk(KERN_ERR "invalid adsp_map[%d] = %d\n", snd_printk(KERN_ERR "invalid adsp_map[%d] = %d\n",
i, adsp_map[i]); i, adsp_map[i]);
adsp_map[i] = 1; adsp_map[i] = 1;
......
...@@ -42,7 +42,7 @@ static int snd_pcm_dev_free(struct snd_device *device); ...@@ -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_register(struct snd_device *device);
static int snd_pcm_dev_disconnect(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 inline struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
{ {
struct snd_pcm *pcm; struct snd_pcm *pcm;
...@@ -53,6 +53,37 @@ static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device) ...@@ -53,6 +53,37 @@ static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device)
return NULL; return NULL;
} }
static inline 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 inline 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, static int snd_pcm_control_ioctl(struct snd_card *card,
struct snd_ctl_file *control, struct snd_ctl_file *control,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
...@@ -65,14 +96,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card, ...@@ -65,14 +96,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card,
if (get_user(device, (int __user *)arg)) if (get_user(device, (int __user *)arg))
return -EFAULT; return -EFAULT;
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
device = device < 0 ? 0 : device + 1; device = snd_pcm_next(card, device);
while (device < SNDRV_PCM_DEVICES) {
if (snd_pcm_search(card, device))
break;
device++;
}
if (device == SNDRV_PCM_DEVICES)
device = -1;
mutex_unlock(&register_mutex); mutex_unlock(&register_mutex);
if (put_user(device, (int __user *)arg)) if (put_user(device, (int __user *)arg))
return -EFAULT; return -EFAULT;
...@@ -98,7 +122,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card, ...@@ -98,7 +122,7 @@ static int snd_pcm_control_ioctl(struct snd_card *card,
if (get_user(subdevice, &info->subdevice)) if (get_user(subdevice, &info->subdevice))
return -EFAULT; return -EFAULT;
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
pcm = snd_pcm_search(card, device); pcm = snd_pcm_get(card, device);
if (pcm == NULL) { if (pcm == NULL) {
err = -ENXIO; err = -ENXIO;
goto _error; goto _error;
...@@ -931,11 +955,11 @@ static int snd_pcm_dev_register(struct snd_device *device) ...@@ -931,11 +955,11 @@ static int snd_pcm_dev_register(struct snd_device *device)
snd_assert(pcm != NULL && device != NULL, return -ENXIO); snd_assert(pcm != NULL && device != NULL, return -ENXIO);
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
if (snd_pcm_search(pcm->card, pcm->device)) { err = snd_pcm_add(pcm);
if (err) {
mutex_unlock(&register_mutex); mutex_unlock(&register_mutex);
return -EBUSY; return err;
} }
list_add_tail(&pcm->list, &snd_pcm_devices);
for (cidx = 0; cidx < 2; cidx++) { for (cidx = 0; cidx < 2; cidx++) {
int devtype = -1; int devtype = -1;
if (pcm->streams[cidx].substream == NULL) if (pcm->streams[cidx].substream == NULL)
......
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#include <linux/kmod.h> #include <linux/kmod.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#define SNDRV_OS_MINORS 256
static int major = CONFIG_SND_MAJOR; static int major = CONFIG_SND_MAJOR;
int snd_major; int snd_major;
EXPORT_SYMBOL(snd_major); EXPORT_SYMBOL(snd_major);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment