[PATCH] ALSA: Fix dynamic major number assignment
From: Sreeraj S Kurup
Date: Wed Nov 25 2026 - 02:33:19 EST
When major is set to 0, register_chrdev() allocates
a major number and returns it.
Store the allocated major number and update snd_major
after successful registration.
This ensures ALSA uses the correct major number for
device registration and unregistration.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
sound/core/sound.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 24f40763a20c..eaead62cf814 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -396,7 +396,6 @@ static int __init alsa_sound_init(void)
{
int err;
- snd_major = major;
snd_ecards_limit = cards_limit;
err = register_chrdev(major, "alsa", &snd_fops);
@@ -405,6 +404,10 @@ static int __init alsa_sound_init(void)
return err;
}
+ if (major == 0)
+ major = err;
+ snd_major = major;
+
err = snd_info_init();
if (err < 0) {
unregister_chrdev(major, "alsa");
--
2.55.0