ALSA: hda - check NULL pointer when creating SPDIF PCM switch
PATCH 1/1 ALSA: hda - check NULL pointer when creating SPDIF PCM switch
From: Mengdong Lin <[email protected]>
If the new control cannot be created, this function will return to avoid snd_hda_ctl_add dereferencing a NULL control pointer.
Signed-off-by Mengdong Lin <[email protected]>
sound/pci/hda/hda_codec.c +7 -2
@@ -3433,11 +3433,16 @@ static struct snd_kcontrol_new spdif_share_sw = {int snd_hda_create_spdif_share_sw (struct hda_codec *codec,struct hda_multi_out *mout) { +struct snd_kcontrol *kctl; +if (!mout->dig_out_nid)return 0 ; + + kctl =snd_ctl_new1 (&spdif_share_sw, mout); +if (!kctl) +return -ENOMEM ;/* ATTENTION: here mout is passed as private_data, instead of codec */ -return snd_hda_ctl_add (codec, mout->dig_out_nid, -snd_ctl_new1 (&spdif_share_sw, mout)); +return snd_hda_ctl_add (codec, mout->dig_out_nid, kctl); }EXPORT_SYMBOL_HDA (snd_hda_create_spdif_share_sw);
Signature · 1 line
1.7.10.4
Takashi Iwai
AppliedAt Thu, 7 Mar 2013 14:11:05 -0500,
Quoted 7 lines · [email protected] wrote:
From: Mengdong Lin <[email protected]>
If the new control cannot be created, this function will return to avoid
snd_hda_ctl_adddereferencing a NULL control pointer.Signed-off-by Mengdong Lin <[email protected]>
Applied.
Another option would be to change snd_hda_ctl_add() to check NULL by itself like snd_ctl_add(), but here is the only place where missing the NULL check, so I don't think it's worth to change more.
thanks,
Takashi
Quoted 27 lines
sound/pci/hda/hda_codec.c +7
-2@@ -3433,11 +3433,16 @@ static struct snd_kcontrol_new spdif_share_sw = {int snd_hda_create_spdif_share_sw (struct hda_codec *codec,struct hda_multi_out *mout) { +struct snd_kcontrol *kctl; +if (!mout->dig_out_nid)return 0 ; + + kctl =snd_ctl_new1 (&spdif_share_sw, mout); +if (!kctl) +return -ENOMEM ;/* ATTENTION: here mout is passed as private_data, instead of codec */ -return snd_hda_ctl_add (codec, mout->dig_out_nid, -snd_ctl_new1 (&spdif_share_sw, mout)); +return snd_hda_ctl_add (codec, mout->dig_out_nid, kctl); }EXPORT_SYMBOL_HDA (snd_hda_create_spdif_share_sw);Signature · 1 line
1.7.10.4