[PATCH] ALSA: gus: check PCM volume control allocation

Ruoyu Wang posted 1 patch 1 day ago
sound/isa/gus/gus_pcm.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] ALSA: gus: check PCM volume control allocation
Posted by Ruoyu Wang 1 day ago
snd_gf1_pcm_new() creates a PCM volume control and then updates
kctl->id.index before adding it to the card. snd_ctl_new1() can return
NULL on allocation failure, so the id update can dereference NULL before
snd_ctl_add() can handle the error.

Return -ENOMEM when the control allocation fails.

Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 sound/isa/gus/gus_pcm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index a0757e1ede465..08ccb4d80adeb 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -851,6 +851,8 @@ int snd_gf1_pcm_new(struct snd_gus_card *gus, int pcm_dev, int control_index)
 		kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control1, gus);
 	else
 		kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control, gus);
+	if (!kctl)
+		return -ENOMEM;
 	kctl->id.index = control_index;
 	err = snd_ctl_add(card, kctl);
 	if (err < 0)
-- 
2.34.1