From: phucduc.bui@gmail.com
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: cassiogabrielcontato@gmail.com, Kees Cook <kees@kernel.org>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH] ALSA: core: propagate actual error code from register_chrdev
Date: Fri, 3 Jul 2026 17:38:40 +0700 [thread overview]
Message-ID: <20260703103840.253527-1-phucduc.bui@gmail.com> (raw)
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/sound.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 8d05fe0d263b..3e1969a52b21 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -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
--
2.43.0
next reply other threads:[~2026-07-03 10:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 10:38 phucduc.bui [this message]
2026-07-03 11:07 ` [PATCH] ALSA: core: propagate actual error code from register_chrdev Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260703103840.253527-1-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=cassiogabrielcontato@gmail.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox