Skip to contentSkip to conversation

ALSA: Fix limit of 8 PCM devices in SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE

PATCH In review Pawel MOLL 3 participants 7 messages Jul 29, 2008 – Jul 30, 2008 Sound

lore
Share & tools
lore

Pawel MOLL

author
#0 lore raw

PATCH 1/1 ALSA: Fix limit of 8 PCM devices in SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE

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.

include/sound/minors.h +2 -0
index 46bcd20..a81798a 100644
@@ -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)
include/sound/pcm.h +1 -3
index 51d58cc..bfc096a 100644
@@ -84,8 +84,6 @@ struct snd_pcm_ops {
  *
  */
 
-#define SNDRV_PCM_DEVICES		8
-
 #define SNDRV_PCM_IOCTL1_FALSE		((void *)0)
 #define SNDRV_PCM_IOCTL1_TRUE		((void *)1)
 
@@ -416,7 +414,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;
sound/core/oss/pcm_oss.c +5 -5
index 4c601b1..4ccd761 100644
@@ -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)
 {
 	pcm->oss.reg = 0;
-	if (dsp_map[pcm->card->number] == (int)pcm->device) {
+	if (dsp_map[pcm->card->number] == pcm->device) {
 		char name[128];
 		int duplex;
 		register_oss_dsp(pcm, 0);
@@ -2963,7 +2963,7 @@ static int snd_pcm_oss_register_minor(struct snd_pcm *pcm)
 		pcm->oss.reg++;
 		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);
 		pcm->oss.reg++;
 		pcm->oss.reg_mask |= 2;
@@ -2988,7 +2988,7 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)
 			snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
 						  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
 			snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_AUDIO, pcm->card->number);
 #endif
@@ -3019,12 +3019,12 @@ static int __init alsa_pcm_oss_init(void)
 
 	/* check device map table */
 	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",
 				   i, dsp_map[i]);
 			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",
 				   i, adsp_map[i]);
 			adsp_map[i] = 1;
sound/core/pcm.c +37 -13

82 lines not on this page · raw message

sound/core/sound.c +0 -2
index 1003ae3..838dd9e 100644
@@ -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);
Signature · 1 line
1.5.5.1
maintainer
#1 lore raw
Quoted 1 line · Pawel MOLL

ALSA: Fix limit of 8 PCM devices in SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE

Thanks. Applied to my GIT tree.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

#2 lore raw
In reply to Pawel MOLL

At Tue, 29 Jul 2008 17:34:26 +0100,

Quoted 15 lines · Pawel MOLL

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.

Quoted 4 lines

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.

Well, the comparison isn't so problematic usually. The unneeded casts are found in many places simply to shut crap warnings by old buggy gcc. But, it's fine to make it int again.

Quoted 3 lines

There is just one more place where
device number is unsigned - in struct snd_pcm_info, which should be also sorted out in future.

Could you split this as a separate patch? This unsigned int -> int change is irrelevant with the fix for 8 PCM devices limit.

Other review comments below.

Quoted 69 lines
include/sound/minors.h +2 -0
index 46bcd20..a81798a 100644
@@ -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)
include/sound/pcm.h +1 -3
index 51d58cc..bfc096a 100644
@@ -84,8 +84,6 @@ struct snd_pcm_ops {
  *
  */
 
-#define SNDRV_PCM_DEVICES		8
-
 #define SNDRV_PCM_IOCTL1_FALSE		((void *)0)
 #define SNDRV_PCM_IOCTL1_TRUE		((void *)1)
 
@@ -416,7 +414,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;
sound/core/oss/pcm_oss.c +3 -3
index 4c601b1..4ccd761 100644
@@ -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)
 {
 	pcm->oss.reg = 0;
-	if (dsp_map[pcm->card->number] == (int)pcm->device) {
+	if (dsp_map[pcm->card->number] == pcm->device) {
 		char name[128];
 		int duplex;
 		register_oss_dsp(pcm, 0);
@@ -2963,7 +2963,7 @@ static int snd_pcm_oss_register_minor(struct snd_pcm *pcm)
 		pcm->oss.reg++;
 		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);
 		pcm->oss.reg++;
 		pcm->oss.reg_mask |= 2;
@@ -2988,7 +2988,7 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)
 			snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
 						  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
 			snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_AUDIO, pcm->card->number);
 #endif

sound/core/oss/pcm_oss.c static int __init alsa_pcm_oss_init(void) · line 3022

Quoted 5 lines
sound/core/oss/pcm_oss.c +1 -1
@@ -3019,12 +3019,12 @@ static int __init alsa_pcm_oss_init(void)
 
 	/* check device map table */
 	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) {

You cannot use SNDRV_OS_MINORS unconditionally here.
In the case DYNAMIC_MINORS=n, SNDRV_PCM_DEVICES is still valid. Maybe better to define SNDRV_PCM_DEVICES with ifdef, such as,

#ifdef CONFIG_SND_DYNAMIC_MINORS
#define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
#else
#define SNDRV_PCM_DEVICES 8
#endif

sound/core/oss/pcm_oss.c static int __init alsa_pcm_oss_init(void) · line 3027

Quoted 6 lines
sound/core/oss/pcm_oss.c +1 -1
 			snd_printk(KERN_ERR "invalid dsp_map[%d] = %d\n",
 				   i, dsp_map[i]);
 			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) {

Ditto.

sound/core/pcm.c static int snd_pcm_dev_free(struct snd_device *device); · line 45

Quoted 13 lines
sound/core/oss/pcm_oss.c +0 -0
 			snd_printk(KERN_ERR "invalid adsp_map[%d] = %d\n",
 				   i, adsp_map[i]);
 			adsp_map[i] = 1;
sound/core/pcm.c +1 -1
index 9dd9bc7..df4c8a3 100644
@@ -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 inline struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)

Don't use inline. It's good for a single-line or a pretty small function, but not for else. The compiler is clever enough to inline the functions automatically if needed.

Also, any reason to rename to *_get()? get() is usually paired with put().

sound/core/pcm.c static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device) · line 56

Quoted 8 lines
sound/core/pcm.c +1 -0
 {
 	struct snd_pcm *pcm;
 
@@ -53,6 +53,37 @@ static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device)
 	return NULL;
 }
 
+static inline int snd_pcm_next(struct snd_card *card, int device)

No inline please.

sound/core/pcm.c static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device) · line 69

Quoted 13 lines
sound/core/pcm.c +13 -0
+{
+	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)

Ditto.

Otherwise it looks like a really nice fix.

Thanks!

Takashi

author
#3 lore raw
Quoted 2 lines

Could you split this as a separate patch? This unsigned int -> int change is irrelevant with the fix for 8 PCM devices limit.

Well, actually it is :-) Take a look here:

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;
}

When device = -1 (first step on enumeration) the expression:

(unsigned)pcm->device > (unsigned)device

will be always 0 as (unsigned)-1 == 0xffffffff...

I wouldn't touch this at all in other case ;-)

Quoted 9 lines

You cannot use SNDRV_OS_MINORS unconditionally here.
In the case DYNAMIC_MINORS=n, SNDRV_PCM_DEVICES is still valid. Maybe better to define SNDRV_PCM_DEVICES with ifdef, such as,

#ifdef CONFIG_SND_DYNAMIC_MINORS
#define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
#else
#define SNDRV_PCM_DEVICES 8
#endif

To be perfectly honest I don't see the point, as in both cases the value may be simply wrong (I mean device not existing at all), so as for me these checks are just "safety fuses" and above is yet another #ifdef, but no problem - I will revive this constant.

Quoted 8 lines
Quoted 1 line

-static struct snd_pcm *snd_pcm_search(struct snd_card *card, int

device)

Quoted 1 line

+static inline struct snd_pcm *snd_pcm_get(struct snd_card *card,

int device)

Don't use inline. It's good for a single-line or a pretty small function, but not for else. The compiler is clever enough to inline the functions automatically if needed.

Well, I used to define functions which are called from just one place (which are usually just an extracted part of other huge function ;-) as inline, but as you wish - I wont persist on it.

Quoted 2 lines

Also, any reason to rename to *_get()? get() is usually paired with put().

I see your point. My motivation was: this function is not used for searching the list any more, just for getting a reference to one, defined element. Of course I can leave it as it was.

Regards

Paweł

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw

At Wed, 30 Jul 2008 11:45:48 +0100,

Quoted 7 lines · Pawel MOLL
Quoted 3 lines

Could you split this as a separate patch? This unsigned int -> int change is irrelevant with the fix for 8 PCM devices limit.

Well, actually it is :-) Take a look here:

static inline int snd_pcm_next(struct snd_card *card, int device)

Quoted 12 lines
{
        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;
}

Ah yeah, this new part contains it.

Quoted 19 lines

When device = -1 (first step on enumeration) the expression:

(unsigned)pcm->device > (unsigned)device

will be always 0 as (unsigned)-1 == 0xffffffff...

I wouldn't touch this at all in other case ;-)

Quoted 9 lines

You cannot use SNDRV_OS_MINORS unconditionally here.
In the case DYNAMIC_MINORS=n, SNDRV_PCM_DEVICES is still valid. Maybe better to define SNDRV_PCM_DEVICES with ifdef, such as,

#ifdef CONFIG_SND_DYNAMIC_MINORS
#define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
#else
#define SNDRV_PCM_DEVICES 8
#endif

Quoted 4 lines

To be perfectly honest I don't see the point, as in both cases the value may be simply wrong (I mean device not existing at all), so as for me these checks are just "safety fuses" and above is yet another #ifdef, but no problem - I will revive this constant.

Yes, it's for safety reason. And, no reason to break old behavior. In slightest case, it can be a regression :)

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

-static struct snd_pcm *snd_pcm_search(struct snd_card *card, int

device)

Quoted 1 line

+static inline struct snd_pcm *snd_pcm_get(struct snd_card *card,

int device)

Quoted 7 lines
Quoted 3 lines

Don't use inline. It's good for a single-line or a pretty small function, but not for else. The compiler is clever enough to inline the functions automatically if needed.

Well, I used to define functions which are called from just one place (which are usually just an extracted part of other huge function ;-) as inline, but as you wish - I wont persist on it.

Especially in such a case, you really don't have to make it inline.

Quoted 6 lines
Quoted 2 lines

Also, any reason to rename to *_get()? get() is usually paired with put().

I see your point. My motivation was: this function is not used for searching the list any more, just for getting a reference to one, defined element. Of course I can leave it as it was.

OK, point taken. No big problem to rename, but I just wondered.

thanks,

Takashi

author
#5 lore raw

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.

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 ;-)

include/sound/minors.h +2 -0
index 46bcd20..a81798a 100644
@@ -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)
include/sound/pcm.h +7 -2
index 51d58cc..5dd8ea4 100644
@@ -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;
sound/core/pcm.c +37 -13

82 lines not on this page · raw message

sound/core/sound.c +0 -2
index 1003ae3..838dd9e 100644
@@ -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);
#6 lore raw

At Wed, 30 Jul 2008 12:46:40 +0100,

Quoted 14 lines · Pawel MOLL

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.

Quoted 5 lines

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 ;-)

Thanks. Applied this one.

Takashi