From: Hanxiang Xu <xuhx@hust.edu.cn>
To: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized
Date: Tue, 2 Dec 2026 10:13:02 +0800 [thread overview]
Message-ID: <20261202101302.1-1-xuhx@hust.edu.cn> (raw)
snd_emux_register() creates and registers the hwdep device
(snd_emux_init_hwdep() -> snd_card_register()) before
snd_emux_init_seq() fills emu->portptrs[], and ignores the init_seq()
return value. A SNDRV_EMUX_IOCTL_MISC_MODE ioctl arriving inside that
window walks emu->portptrs[i]->ctrls[] with portptrs[i] == NULL and
causes a near-NULL kernel write (dynamically confirmed on v7.4-rc5);
a failed sequencer setup additionally leaves the already-registered
hwdep behind for the probe error path to free with possibly-open fds.
Initialize the ports (and OSS/virmidi) first and create the hwdep
device last, so the device only becomes visible to userspace after
everything its ioctls touch is initialized, and propagate the
snd_emux_init_seq() error.
Cc: <stable@vger.kernel.org>
Signed-off-by: Hanxiang Xu <xuhx@hust.edu.cn>
---
sound/synth/emux/emux.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c
index 4352c57..518019e 100644
--- a/sound/synth/emux/emux.c
+++ b/sound/synth/emux/emux.c
@@ -107,18 +107,19 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch
if (emu->sflist == NULL)
return -ENOMEM;
- err = snd_emux_init_hwdep(emu);
- if (err < 0)
- return err;
-
snd_emux_init_voices(emu);
- snd_emux_init_seq(emu, card, index);
+ if (snd_emux_init_seq(emu, card, index) < 0)
+ return -ENODEV;
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
snd_emux_init_seq_oss(emu);
#endif
snd_emux_init_virmidi(emu, card);
+ err = snd_emux_init_hwdep(emu);
+ if (err < 0)
+ return err;
+
snd_emux_proc_init(emu, card, index);
return 0;
}
--
2.43.0
reply other threads:[~2026-12-02 3:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261202101302.1-1-xuhx@hust.edu.cn \
--to=xuhx@hust.edu.cn \
--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
all inboxes | Powered by JetHome®