Re: [PATCH] ALSA: emux: expose the hwdep device only after ports are initialized

From: Takashi Iwai

Date: Wed Dec 02 2026 - 04:01:29 EST


On Wed, 02 Dec 2026 03:13:02 +0100,
Hanxiang Xu wrote:
>
> 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@xxxxxxxxxxxxxxx>
> Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>

Applied to for-next branch. Thanks.


Takashi