ALSA: core: propagate actual error code from register_chrdev
PATCH 1/1 ALSA: core: propagate actual error code from register_chrdev
From: bui duc phuc <[email protected]>
The alsa_sound_init() function currently returns a hardcoded -EIO if register_chrdev() fails, masking specific error codes from __register_chrdev() such as -EINVAL, -ENOMEM, or -EBUSY.
Masking these failures under a generic -EIO makes system-level diagnostics unnecessarily difficult. Propagating explicit error codes from register_chrdev() is also an established convention widely practiced across other subsystems.
Fix this by capturing and propagating the dynamic error code from register_chrdev(). While at it, also assign the return value of snd_info_init() to the 'err' variable instead of hardcoding -ENOMEM to ensure consistency and future-proofing.
--- sound/core/sound.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
sound/core/sound.c +10 -4
@@ -395,15 +395,21 @@ int __init snd_minor_info_init(void)static int __init alsa_sound_init (void ) { +int err; + snd_major = major; snd_ecards_limit = cards_limit; -if (register_chrdev (major,"alsa" , &snd_fops)) { + + err =register_chrdev (major,"alsa" , &snd_fops); +if (err <0 ) {pr_err ("ALSA core: unable to register native major device number %d\n" , major); -return -EIO ; +return err; } -if (snd_info_init () <0 ) { + + err =snd_info_init (); +if (err <0 ) {unregister_chrdev (major,"alsa" ); -return -ENOMEM ; +return err; }#ifdef CONFIG_SND_DEBUG
Signature · 1 line
2.43.0
Takashi Iwai
AppliedQuoted 12 lines · On Fri, 03 Jul 2026 12:38:40 +0200, [email protected] wrote:
From: bui duc phuc <[email protected]>
The
alsa_sound_init()function currently returns a hardcoded-EIOifregister_chrdev()fails, masking specific error codes from__register_chrdev()such as-EINVAL,-ENOMEM, or-EBUSY.Masking these failures under a generic
-EIOmakes system-level diagnostics unnecessarily difficult. Propagating explicit error codes fromregister_chrdev()is also an established convention widely practiced across other subsystems.
Quoted 6 lines
Fix this by capturing and propagating the dynamic error code from
register_chrdev(). While at it, also assign the return value ofsnd_info_init()to the 'err' variable instead of hardcoding-ENOMEMto ensure consistency and future-proofing.Signed-off-by bui duc phuc <[email protected]>
Applied to for-next branch now. Thanks.
Takashi