ALSA: es18xx: check control allocation before private data setup
PATCH v2 1/1 ALSA: es18xx: check control allocation before private data setup
snd_es18xx_mixer() creates controls with snd_ctl_new1() and then stores bookkeeping pointers or sets private_free before calling snd_ctl_add(). snd_ctl_new1() can return NULL on allocation failure, so those writes can dereference a NULL control pointer.
Check the returned control pointers before using them and return -ENOMEM on allocation failure.
---
v2:
- Rebase on sound.git for-next.
- Resend only es18xx; the other v1 patches are already in for-next.
sound/isa/es18xx.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/isa/es18xx.c +4 -0
@@ -1762,6 +1762,8 @@ static int snd_es18xx_mixer(struct snd_card *card)for (idx =0 ; idx <ARRAY_SIZE (snd_es18xx_base_controls); idx++) {struct snd_kcontrol *kctl; kctl =snd_ctl_new1 (&snd_es18xx_base_controls[idx], chip); +if (!kctl) +return -ENOMEM ;if (chip->caps &ES18XX_HWV ) {switch (idx) {case 0 :
@@ -1823,6 +1825,8 @@ static int snd_es18xx_mixer(struct snd_card *card)for (idx =0 ; idx <ARRAY_SIZE (snd_es18xx_hw_volume_controls); idx++) {struct snd_kcontrol *kctl; kctl =snd_ctl_new1 (&snd_es18xx_hw_volume_controls[idx], chip); +if (!kctl) +return -ENOMEM ;if (idx ==0 ) chip->hw_volume = kctl;else
Signature · 1 line
2.51.0
Takashi Iwai
AppliedQuoted 6 lines · Ruoyu Wang
snd_es18xx_mixer()creates controls withsnd_ctl_new1()and then stores bookkeeping pointers or setsprivate_freebefore callingsnd_ctl_add().snd_ctl_new1()can return NULL on allocation failure, so those writes can dereference a NULL control pointer.
Quoted 8 lines
Check the returned control pointers before using them and return
-ENOMEMon allocation failure.Signed-off-by Ruoyu Wang <[email protected]>---
v2:
- Rebase on sound.git for-next.
- Resend only es18xx; the other v1 patches are already in for-next.
Applied to for-next branch now. Thanks.
Takashi