ALSA: hda - fix ELD memory leak

memset(eld) clears eld->proc_entry which will leak the struct
snd_info_entry when unloading module.

Fix it by
- memset only the fields before eld->eld_buffer
- set eld->eld_valid to true _after_ all eld fields have been filled

Cc: <stable@kernel.org>
Cc: Pierre-louis Bossart <pierre-louis.bossart@intel.com>
Acked-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Wu Fengguang 2011-11-16 16:29:46 +08:00 committed by Takashi Iwai
parent e53de8f00c
commit b95d68b817
3 changed files with 9 additions and 10 deletions

View File

@ -297,10 +297,10 @@ static int hdmi_update_eld(struct hdmi_eld *e,
buf + ELD_FIXED_BYTES + mnl + 3 * i); buf + ELD_FIXED_BYTES + mnl + 3 * i);
} }
e->eld_valid = true;
return 0; return 0;
out_fail: out_fail:
e->eld_ver = 0;
return -EINVAL; return -EINVAL;
} }
@ -323,9 +323,6 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
* ELD is valid, actual eld_size is assigned in hdmi_update_eld() * ELD is valid, actual eld_size is assigned in hdmi_update_eld()
*/ */
if (!eld->eld_valid)
return -ENOENT;
size = snd_hdmi_get_eld_size(codec, nid); size = snd_hdmi_get_eld_size(codec, nid);
if (size == 0) { if (size == 0) {
/* wfg: workaround for ASUS P5E-VM HDMI board */ /* wfg: workaround for ASUS P5E-VM HDMI board */

View File

@ -653,6 +653,9 @@ struct hdmi_eld {
int spk_alloc; int spk_alloc;
int sad_count; int sad_count;
struct cea_sad sad[ELD_MAX_SAD]; struct cea_sad sad[ELD_MAX_SAD];
/*
* all fields above eld_buffer will be cleared before updating ELD
*/
char eld_buffer[ELD_MAX_SIZE]; char eld_buffer[ELD_MAX_SIZE];
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
struct snd_info_entry *proc_entry; struct snd_info_entry *proc_entry;

View File

@ -980,20 +980,19 @@ static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
* the unsolicited response to avoid custom WARs. * the unsolicited response to avoid custom WARs.
*/ */
int present = snd_hda_pin_sense(codec, pin_nid); int present = snd_hda_pin_sense(codec, pin_nid);
bool eld_valid = false;
memset(eld, 0, sizeof(*eld)); memset(eld, 0, offsetof(struct hdmi_eld, eld_buffer));
eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
if (eld->monitor_present) if (eld->monitor_present)
eld->eld_valid = !!(present & AC_PINSENSE_ELDV); eld_valid = !!(present & AC_PINSENSE_ELDV);
else
eld->eld_valid = 0;
printk(KERN_INFO printk(KERN_INFO
"HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n", "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
codec->addr, pin_nid, eld->monitor_present, eld->eld_valid); codec->addr, pin_nid, eld->monitor_present, eld_valid);
if (eld->eld_valid) if (eld_valid)
if (!snd_hdmi_get_eld(eld, codec, pin_nid)) if (!snd_hdmi_get_eld(eld, codec, pin_nid))
snd_hdmi_show_eld(eld); snd_hdmi_show_eld(eld);