The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] ALSA: Fix dynamic major number assignment
@ 2026-11-25  7:30 Sreeraj S Kurup
  2026-11-25  7:41 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Sreeraj S Kurup @ 2026-11-25  7:30 UTC (permalink / raw)
  To: perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: Fix dynamic major number assignment
  2026-11-25  7:30 [PATCH] ALSA: Fix dynamic major number assignment Sreeraj S Kurup
@ 2026-11-25  7:41 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-25  7:41 UTC (permalink / raw)
  To: Sreeraj S Kurup; +Cc: perex, tiwai, linux-kernel, linux-sound

On Wed, 25 Nov 2026 08:30:09 +0100,
Sreeraj S Kurup wrote:
> 
> 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@gmail.com>

We never thought of the dynamic major assignment there.
So major=0 should be treated simply as an error before passing to
register_chrdev().

Moreover, the current code was written before module_param_named() is
used widely, and that's why it has unnecessary assignments.
That is, we can drop major and cards_limit variables, and directly use
snd_major and snd_ecards_limit with initialization and
module_param_named().


thanks,

Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25  7:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  7:30 [PATCH] ALSA: Fix dynamic major number assignment Sreeraj S Kurup
2026-11-25  7:41 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox