* Re: [PATCH] ALSA: Fix dynamic major number assignment
2026-11-25 7:41 ` Takashi Iwai
@ 2026-11-25 8:24 ` Sreeraj S Kurup
2026-11-25 8:30 ` [PATCH v2] ALSA: core: Reject zero major number Sreeraj S Kurup
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Sreeraj S Kurup @ 2026-11-25 8:24 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239
Hi Takashi,
Thanks for your review.
I've updated the patch according to your suggestions. It now rejects major=0 before
calling register_chrdev() and removes the redundant major and cards_limit variables, using
snd_major and snd_ecards_limit directly with module_param_named().
Please review the updated version.
Best regards,
Sreeraj
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2] ALSA: core: Reject zero major number
2026-11-25 7:41 ` Takashi Iwai
2026-11-25 8:24 ` Sreeraj S Kurup
@ 2026-11-25 8:30 ` Sreeraj S Kurup
2026-11-25 8:43 ` [PATCH v3] " Sreeraj S Kurup
2026-11-25 9:35 ` [PATCH v4] " Sreeraj S Kurup
3 siblings, 0 replies; 6+ messages in thread
From: Sreeraj S Kurup @ 2026-11-25 8:30 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239
Reject a zero major number before calling register_chrdev(),
as ALSA expects a fixed major number.
Remove the redundant major and cards_limit variables and
use snd_major and snd_ecards_limit directly with
module_param_named().
Update device number creation and character device
registration and unregistration to use snd_major.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v2:
- Reject major=0 before calling register_chrdev().
- Remove redundant major and cards_limit variables.
- Use snd_major and snd_ecards_limit directly with module_param_named().
- Update device number creation, registration and unregistration to use snd_major.
sound/core/sound.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 24f40763a20c..8ac3cee19e66 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -18,28 +18,25 @@
#include <linux/kmod.h>
#include <linux/mutex.h>
-static int major = CONFIG_SND_MAJOR;
-int snd_major;
+int snd_major = CONFIG_SND_MAJOR;
EXPORT_SYMBOL(snd_major);
-static int cards_limit = 1;
+/* this one holds the actual max. card number currently available.
+ * as default, it's identical with cards_limit option. when more
+ * modules are loaded manually, this limit number increases, too.
+ */
+int snd_ecards_limit = 1;
+EXPORT_SYMBOL(snd_ecards_limit);
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards.");
MODULE_LICENSE("GPL");
-module_param(major, int, 0444);
+module_param_named(major, snd_major, int, 0444);
MODULE_PARM_DESC(major, "Major # for sound driver.");
-module_param(cards_limit, int, 0444);
+module_param_named(cards_limit, snd_ecards_limit, int, 0444);
MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards.");
MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR);
-/* this one holds the actual max. card number currently available.
- * as default, it's identical with cards_limit option. when more
- * modules are loaded manually, this limit number increases, too.
- */
-int snd_ecards_limit;
-EXPORT_SYMBOL(snd_ecards_limit);
-
#ifdef CONFIG_SND_DEBUG
struct dentry *sound_debugfs_root;
EXPORT_SYMBOL_GPL(sound_debugfs_root);
@@ -61,7 +58,7 @@ void snd_request_card(int card)
{
if (snd_card_locked(card))
return;
- if (card < 0 || card >= cards_limit)
+ if (card < 0 || card >= snd_ecards_limit)
return;
request_module("snd-card-%i", card);
}
@@ -280,7 +277,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
}
preg->dev = device;
- device->devt = MKDEV(major, minor);
+ device->devt = MKDEV(snd_major, minor);
err = device_add(device);
if (err < 0)
goto error;
@@ -396,18 +393,19 @@ static int __init alsa_sound_init(void)
{
int err;
- snd_major = major;
- snd_ecards_limit = cards_limit;
+ if (!snd_major)
+ return -EINVAL;
- err = register_chrdev(major, "alsa", &snd_fops);
+ err = register_chrdev(snd_major, "alsa", &snd_fops);
if (err < 0) {
- pr_err("ALSA core: unable to register native major device number %d\n", major);
+ pr_err("ALSA core: unable to register native major device number %d\n",
+ snd_major);
return err;
}
err = snd_info_init();
if (err < 0) {
- unregister_chrdev(major, "alsa");
+ unregister_chrdev(snd_major, "alsa");
return err;
}
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3] ALSA: core: Reject zero major number
2026-11-25 7:41 ` Takashi Iwai
2026-11-25 8:24 ` Sreeraj S Kurup
2026-11-25 8:30 ` [PATCH v2] ALSA: core: Reject zero major number Sreeraj S Kurup
@ 2026-11-25 8:43 ` Sreeraj S Kurup
2026-11-25 9:35 ` [PATCH v4] " Sreeraj S Kurup
3 siblings, 0 replies; 6+ messages in thread
From: Sreeraj S Kurup @ 2026-11-25 8:43 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239
Reject a zero major number before calling register_chrdev(),
as ALSA expects a fixed major number.
Remove the redundant major and cards_limit variables and
use snd_major and snd_ecards_limit directly with
module_param_named().
Update device number creation and character device
registration and unregistration to use snd_major.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v3:
- Update the unregister_chrdev() call in alsa_sound_exit() to use snd_major.
v2:
- Reject major=0 before calling register_chrdev().
- Remove redundant major and cards_limit variables.
- Use snd_major and snd_ecards_limit directly with module_param_named().
- Update device number creation, registration and unregistration to use snd_major.
sound/core/sound.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 24f40763a20c..4c71f2bf440a 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -18,28 +18,25 @@
#include <linux/kmod.h>
#include <linux/mutex.h>
-static int major = CONFIG_SND_MAJOR;
-int snd_major;
+int snd_major = CONFIG_SND_MAJOR;
EXPORT_SYMBOL(snd_major);
-static int cards_limit = 1;
+/* this one holds the actual max. card number currently available.
+ * as default, it's identical with cards_limit option. when more
+ * modules are loaded manually, this limit number increases, too.
+ */
+int snd_ecards_limit = 1;
+EXPORT_SYMBOL(snd_ecards_limit);
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards.");
MODULE_LICENSE("GPL");
-module_param(major, int, 0444);
+module_param_named(major, snd_major, int, 0444);
MODULE_PARM_DESC(major, "Major # for sound driver.");
-module_param(cards_limit, int, 0444);
+module_param_named(cards_limit, snd_ecards_limit, int, 0444);
MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards.");
MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR);
-/* this one holds the actual max. card number currently available.
- * as default, it's identical with cards_limit option. when more
- * modules are loaded manually, this limit number increases, too.
- */
-int snd_ecards_limit;
-EXPORT_SYMBOL(snd_ecards_limit);
-
#ifdef CONFIG_SND_DEBUG
struct dentry *sound_debugfs_root;
EXPORT_SYMBOL_GPL(sound_debugfs_root);
@@ -61,7 +58,7 @@ void snd_request_card(int card)
{
if (snd_card_locked(card))
return;
- if (card < 0 || card >= cards_limit)
+ if (card < 0 || card >= snd_ecards_limit)
return;
request_module("snd-card-%i", card);
}
@@ -280,7 +277,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
}
preg->dev = device;
- device->devt = MKDEV(major, minor);
+ device->devt = MKDEV(snd_major, minor);
err = device_add(device);
if (err < 0)
goto error;
@@ -396,18 +393,19 @@ static int __init alsa_sound_init(void)
{
int err;
- snd_major = major;
- snd_ecards_limit = cards_limit;
+ if (!snd_major)
+ return -EINVAL;
- err = register_chrdev(major, "alsa", &snd_fops);
+ err = register_chrdev(snd_major, "alsa", &snd_fops);
if (err < 0) {
- pr_err("ALSA core: unable to register native major device number %d\n", major);
+ pr_err("ALSA core: unable to register native major device number %d\n",
+ snd_major);
return err;
}
err = snd_info_init();
if (err < 0) {
- unregister_chrdev(major, "alsa");
+ unregister_chrdev(snd_major, "alsa");
return err;
}
@@ -426,7 +424,7 @@ static void __exit alsa_sound_exit(void)
debugfs_remove(sound_debugfs_root);
#endif
snd_info_done();
- unregister_chrdev(major, "alsa");
+ unregister_chrdev(snd_major, "alsa");
}
subsys_initcall(alsa_sound_init);
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v4] ALSA: core: Reject zero major number
2026-11-25 7:41 ` Takashi Iwai
` (2 preceding siblings ...)
2026-11-25 8:43 ` [PATCH v3] " Sreeraj S Kurup
@ 2026-11-25 9:35 ` Sreeraj S Kurup
3 siblings, 0 replies; 6+ messages in thread
From: Sreeraj S Kurup @ 2026-11-25 9:35 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239
Reject a zero major number before calling register_chrdev(),
as ALSA expects a fixed major number.
Remove the redundant major variable and use snd_major
directly with module_param_named().
Keep a separate configured card limit for automatic
module loading, as snd_ecards_limit may increase at
runtime when cards are registered at higher indices.
Update device number creation and character device
registration and unregistration to use snd_major.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v4:
- Keep the configured cards_limit separate from
snd_ecards_limit to preserve the existing autoload behavior.
- Update the comments describing the card limits.
v3:
- Update the unregister_chrdev() call in alsa_sound_exit() to use snd_major.
v2:
- Reject major=0 before calling register_chrdev().
- Remove redundant major and cards_limit variables.
- Use snd_major and snd_ecards_limit directly with module_param_named().
- Update device number creation, registration and unregistration to use snd_major.
sound/core/sound.c | 43 +++++++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 20 deletions(-)
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 24f40763a20c..35b7f1683532 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -18,28 +18,28 @@
#include <linux/kmod.h>
#include <linux/mutex.h>
-static int major = CONFIG_SND_MAJOR;
-int snd_major;
+int snd_major = CONFIG_SND_MAJOR;
EXPORT_SYMBOL(snd_major);
-static int cards_limit = 1;
+/* maximum number of cards allowed for automatic module loading */
+static int snd_cards_limit = 1;
+
+/* this holds the actual maximum card number currently available.
+ * it is initialized from snd_cards_limit and increases when
+ * cards are registered manually at higher indices.
+ */
+int snd_ecards_limit = 1;
+EXPORT_SYMBOL(snd_ecards_limit);
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards.");
MODULE_LICENSE("GPL");
-module_param(major, int, 0444);
+module_param_named(major, snd_major, int, 0444);
MODULE_PARM_DESC(major, "Major # for sound driver.");
-module_param(cards_limit, int, 0444);
+module_param_named(cards_limit, snd_cards_limit, int, 0444);
MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards.");
MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR);
-/* this one holds the actual max. card number currently available.
- * as default, it's identical with cards_limit option. when more
- * modules are loaded manually, this limit number increases, too.
- */
-int snd_ecards_limit;
-EXPORT_SYMBOL(snd_ecards_limit);
-
#ifdef CONFIG_SND_DEBUG
struct dentry *sound_debugfs_root;
EXPORT_SYMBOL_GPL(sound_debugfs_root);
@@ -61,7 +61,7 @@ void snd_request_card(int card)
{
if (snd_card_locked(card))
return;
- if (card < 0 || card >= cards_limit)
+ if (card < 0 || card >= snd_cards_limit)
return;
request_module("snd-card-%i", card);
}
@@ -280,7 +280,7 @@ int snd_register_device(int type, struct snd_card *card, int dev,
}
preg->dev = device;
- device->devt = MKDEV(major, minor);
+ device->devt = MKDEV(snd_major, minor);
err = device_add(device);
if (err < 0)
goto error;
@@ -396,18 +396,21 @@ static int __init alsa_sound_init(void)
{
int err;
- snd_major = major;
- snd_ecards_limit = cards_limit;
+ if (!snd_major)
+ return -EINVAL;
+
+ snd_ecards_limit = snd_cards_limit;
- err = register_chrdev(major, "alsa", &snd_fops);
+ err = register_chrdev(snd_major, "alsa", &snd_fops);
if (err < 0) {
- pr_err("ALSA core: unable to register native major device number %d\n", major);
+ pr_err("ALSA core: unable to register native major device number %d\n",
+ snd_major);
return err;
}
err = snd_info_init();
if (err < 0) {
- unregister_chrdev(major, "alsa");
+ unregister_chrdev(snd_major, "alsa");
return err;
}
@@ -426,7 +429,7 @@ static void __exit alsa_sound_exit(void)
debugfs_remove(sound_debugfs_root);
#endif
snd_info_done();
- unregister_chrdev(major, "alsa");
+ unregister_chrdev(snd_major, "alsa");
}
subsys_initcall(alsa_sound_init);
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread