diff options
author | Takashi Iwai <tiwai@suse.de> | 2016-03-10 09:49:35 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2016-03-10 09:54:42 -0500 |
commit | 1a414f48d7ccb197b61c18888b72327c98171844 (patch) | |
tree | 49bfce24deaa299602ebf9d0e3d52da40a611944 /sound/hda | |
parent | 8cc1a8ab477e974a3516e73276ef4b6e546c4c65 (diff) |
ALSA: hda - Add a sanity check of pin / port mapping on i915 HDMI/DP
There is an implicit rule to map between pin NID and port number on
Intel HDMI/DP codec: the mapping is fixed only for NID 0x05, 0x06 and
0x07. For avoiding the possible memory corruption, add a sanity check
for the NID value and splat WARN_ON() for invalid accesses.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/hda')
-rw-r--r-- | sound/hda/hdac_i915.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c index f6854dbd7d8d..fb96aead8257 100644 --- a/sound/hda/hdac_i915.c +++ b/sound/hda/hdac_i915.c | |||
@@ -126,6 +126,8 @@ EXPORT_SYMBOL_GPL(snd_hdac_get_display_clk); | |||
126 | */ | 126 | */ |
127 | static int pin2port(hda_nid_t pin_nid) | 127 | static int pin2port(hda_nid_t pin_nid) |
128 | { | 128 | { |
129 | if (WARN_ON(pin_nid < 5 || pin_nid > 7)) | ||
130 | return -1; | ||
129 | return pin_nid - 4; | 131 | return pin_nid - 4; |
130 | } | 132 | } |
131 | 133 | ||
@@ -144,10 +146,14 @@ static int pin2port(hda_nid_t pin_nid) | |||
144 | int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid, int rate) | 146 | int snd_hdac_sync_audio_rate(struct hdac_bus *bus, hda_nid_t nid, int rate) |
145 | { | 147 | { |
146 | struct i915_audio_component *acomp = bus->audio_component; | 148 | struct i915_audio_component *acomp = bus->audio_component; |
149 | int port; | ||
147 | 150 | ||
148 | if (!acomp || !acomp->ops || !acomp->ops->sync_audio_rate) | 151 | if (!acomp || !acomp->ops || !acomp->ops->sync_audio_rate) |
149 | return -ENODEV; | 152 | return -ENODEV; |
150 | return acomp->ops->sync_audio_rate(acomp->dev, pin2port(nid), rate); | 153 | port = pin2port(nid); |
154 | if (port < 0) | ||
155 | return -EINVAL; | ||
156 | return acomp->ops->sync_audio_rate(acomp->dev, port, rate); | ||
151 | } | 157 | } |
152 | EXPORT_SYMBOL_GPL(snd_hdac_sync_audio_rate); | 158 | EXPORT_SYMBOL_GPL(snd_hdac_sync_audio_rate); |
153 | 159 | ||
@@ -175,11 +181,15 @@ int snd_hdac_acomp_get_eld(struct hdac_bus *bus, hda_nid_t nid, | |||
175 | bool *audio_enabled, char *buffer, int max_bytes) | 181 | bool *audio_enabled, char *buffer, int max_bytes) |
176 | { | 182 | { |
177 | struct i915_audio_component *acomp = bus->audio_component; | 183 | struct i915_audio_component *acomp = bus->audio_component; |
184 | int port; | ||
178 | 185 | ||
179 | if (!acomp || !acomp->ops || !acomp->ops->get_eld) | 186 | if (!acomp || !acomp->ops || !acomp->ops->get_eld) |
180 | return -ENODEV; | 187 | return -ENODEV; |
181 | 188 | ||
182 | return acomp->ops->get_eld(acomp->dev, pin2port(nid), audio_enabled, | 189 | port = pin2port(nid); |
190 | if (port < 0) | ||
191 | return -EINVAL; | ||
192 | return acomp->ops->get_eld(acomp->dev, port, audio_enabled, | ||
183 | buffer, max_bytes); | 193 | buffer, max_bytes); |
184 | } | 194 | } |
185 | EXPORT_SYMBOL_GPL(snd_hdac_acomp_get_eld); | 195 | EXPORT_SYMBOL_GPL(snd_hdac_acomp_get_eld); |