[PATCH] ALSA: cmipci: check S/PDIF control allocations
Ruoyu Wang <[email protected]> Sun, 7 Jun 2026 10:56:08 +0800
| Newsgroups | org.alsa-project.alsa-devel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
snd_cmipci_mixer_new() creates several S/PDIF controls and adjusts kctl->id.device before adding each control to the card. If snd_ctl_new1() returns NULL, the id update dereferences NULL before snd_ctl_add() can reject the missing control. Check each S/PDIF control allocation before setting the device id. Signed-off-by: Ruoyu Wang <[email protected]> --- sound/pci/cmipci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c index cd73b68336394..ff4bfbf94b81b 100644 --- a/sound/pci/cmipci.c +++ b/sound/pci/cmipci.c @@ -2637,16 +2637,22 @@ static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device) } if (cm->can_ac3_hw) { kctl = snd_ctl_new1(&snd_cmipci_spdif_default, cm); + if (!kctl) + return -ENOMEM; kctl->id.device = pcm_spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) return err; kctl = snd_ctl_new1(&snd_cmipci_spdif_mask, cm); + if (!kctl) + return -ENOMEM; kctl->id.device = pcm_spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) return err; kctl = snd_ctl_new1(&snd_cmipci_spdif_stream, cm); + if (!kctl) + return -ENOMEM; kctl->id.device = pcm_spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) -- 2.34.1