All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Henningsson <david.henningsson@canonical.com>
To: tiwai@suse.de, alsa-devel@alsa-project.org,
	fengguang.wu@intel.com, pierre-louis.bossart@linux.intel.com
Cc: David Henningsson <david.henningsson@canonical.com>
Subject: [PATCH 2/3] ALSA: hda - hdmi: Do not expose eld data when eld is invalid
Date: Mon, 18 Feb 2013 14:11:12 +0100	[thread overview]
Message-ID: <1361193073-7199-3-git-send-email-david.henningsson@canonical.com> (raw)
In-Reply-To: <1361193073-7199-1-git-send-email-david.henningsson@canonical.com>

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>
---
 sound/pci/hda/patch_hdmi.c |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 32adaa6..9236cdb 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -343,14 +343,17 @@ static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
 			struct snd_ctl_elem_info *uinfo)
 {
 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-	struct hdmi_spec *spec;
+	struct hdmi_spec *spec = codec->spec;
+	struct hdmi_eld *eld;
 	int pin_idx;
 
-	spec = codec->spec;
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
 
 	pin_idx = kcontrol->private_value;
-	uinfo->count = spec->pins[pin_idx].sink_eld.eld_size;
+	eld = &spec->pins[pin_idx].sink_eld;
+
+	if (eld->eld_valid)
+		uinfo->count = eld->eld_valid ? eld->eld_size : 0;
 
 	return 0;
 }
@@ -359,14 +362,21 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
 			struct snd_ctl_elem_value *ucontrol)
 {
 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-	struct hdmi_spec *spec;
+	struct hdmi_spec *spec = codec->spec;
+	struct hdmi_eld *eld;
 	int pin_idx;
 
-	spec = codec->spec;
 	pin_idx = kcontrol->private_value;
+	eld = &spec->pins[pin_idx].sink_eld;
+
+	if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
+		snd_BUG();
+		return -EINVAL;
+	}
 
-	memcpy(ucontrol->value.bytes.data,
-		spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE);
+	if (eld->eld_valid)
+		memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
+		       eld->eld_size);
 
 	return 0;
 }
-- 
1.7.9.5

  parent reply	other threads:[~2013-02-18 13:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-18 13:11 [PATCH 0/3] Make HDMI ELD usable with hotplug David Henningsson
2013-02-18 13:11 ` [PATCH 1/3] ALSA: hda - hdmi: ELD shouldn't be valid after unplug David Henningsson
2013-02-18 13:11 ` David Henningsson [this message]
2013-02-18 14:39   ` [PATCH 2/3] ALSA: hda - hdmi: Do not expose eld data when eld is invalid Takashi Iwai
2013-02-18 13:11 ` [PATCH 3/3] ALSA: hda - hdmi: Notify userspace when ELD control changes David Henningsson
2013-02-18 14:41   ` Takashi Iwai
2013-02-18 14:46     ` David Henningsson
2013-02-18 14:55       ` Takashi Iwai
2013-02-18 15:09         ` David Henningsson
2013-02-18 15:14           ` Takashi Iwai
2013-02-18 16:08             ` David Henningsson
2013-02-18 16:21               ` Takashi Iwai
2013-02-18 13:35 ` [PATCH 0/3] Make HDMI ELD usable with hotplug Takashi Iwai
2013-02-18 13:50   ` David Henningsson
2013-02-18 14:28     ` Takashi Iwai
2013-02-18 14:33       ` Takashi Iwai
2013-02-18 22:39     ` Ville Syrjälä
2013-02-19  2:39       ` Wang xingchao
2013-02-19  5:55       ` David Henningsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1361193073-7199-3-git-send-email-david.henningsson@canonical.com \
    --to=david.henningsson@canonical.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=fengguang.wu@intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.