[PATCH] ALSA: ice1724: check S/PDIF control allocations

Ruoyu Wang posted 1 patch 1 day ago
sound/pci/ice1712/ice1724.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] ALSA: ice1724: check S/PDIF control allocations
Posted by Ruoyu Wang 1 day ago
snd_vt1724_spdif_build_controls() creates S/PDIF controls and then sets
kctl->id.device before calling snd_ctl_add(). snd_ctl_new1() can return
NULL on allocation failure, so these device-id writes can dereference
NULL.

Check each live control allocation before using the returned pointer.

Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 sound/pci/ice1712/ice1724.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 65bf48647d089..b16c84983b81a 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -2379,16 +2379,22 @@ static int snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice)
 		return err;
 
 	kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice);
+	if (!kctl)
+		return -ENOMEM;
 	kctl->id.device = ice->pcm->device;
 	err = snd_ctl_add(ice->card, kctl);
 	if (err < 0)
 		return err;
 	kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice);
+	if (!kctl)
+		return -ENOMEM;
 	kctl->id.device = ice->pcm->device;
 	err = snd_ctl_add(ice->card, kctl);
 	if (err < 0)
 		return err;
 	kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice);
+	if (!kctl)
+		return -ENOMEM;
 	kctl->id.device = ice->pcm->device;
 	err = snd_ctl_add(ice->card, kctl);
 	if (err < 0)
-- 
2.34.1