aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_hdmi.c
diff options
context:
space:
mode:
authorDavid Henningsson <david.henningsson@canonical.com>2013-02-19 10:11:23 -0500
committerTakashi Iwai <tiwai@suse.de>2013-02-19 12:28:13 -0500
commit68e03de98507065bb5fd1958388974c9bc2cd480 (patch)
treed6ed5311465005647b4d2ab2bce0d396e422032d /sound/pci/hda/patch_hdmi.c
parentbbfd8a19b6913f50a362457c34d49bfafe5e456e (diff)
ALSA: hda - hdmi: Do not expose eld data when eld is invalid
Previously, it was possible to read the eld data of the previous monitor connected. This should not be allowed. Also refactor the function slightly. Signed-off-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_hdmi.c')
-rw-r--r--sound/pci/hda/patch_hdmi.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 32adaa6c5627..6bcdd667f514 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -343,14 +343,16 @@ static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_info *uinfo) 343 struct snd_ctl_elem_info *uinfo)
344{ 344{
345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
346 struct hdmi_spec *spec; 346 struct hdmi_spec *spec = codec->spec;
347 struct hdmi_eld *eld;
347 int pin_idx; 348 int pin_idx;
348 349
349 spec = codec->spec;
350 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 350 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
351 351
352 pin_idx = kcontrol->private_value; 352 pin_idx = kcontrol->private_value;
353 uinfo->count = spec->pins[pin_idx].sink_eld.eld_size; 353 eld = &spec->pins[pin_idx].sink_eld;
354
355 uinfo->count = eld->eld_valid ? eld->eld_size : 0;
354 356
355 return 0; 357 return 0;
356} 358}
@@ -359,14 +361,23 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol) 361 struct snd_ctl_elem_value *ucontrol)
360{ 362{
361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 363 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
362 struct hdmi_spec *spec; 364 struct hdmi_spec *spec = codec->spec;
365 struct hdmi_eld *eld;
363 int pin_idx; 366 int pin_idx;
364 367
365 spec = codec->spec;
366 pin_idx = kcontrol->private_value; 368 pin_idx = kcontrol->private_value;
369 eld = &spec->pins[pin_idx].sink_eld;
370
371 if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
372 snd_BUG();
373 return -EINVAL;
374 }
367 375
368 memcpy(ucontrol->value.bytes.data, 376 memset(ucontrol->value.bytes.data, 0,
369 spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE); 377 ARRAY_SIZE(ucontrol->value.bytes.data));
378 if (eld->eld_valid)
379 memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
380 eld->eld_size);
370 381
371 return 0; 382 return 0;
372} 383}