Commit 08605068 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Sanity check of access to SPDIF controls array

Put WARN_ON() and bail out if the given index is over the allocated
array of the given SPDIF controls.  It's merely a sanity check to
catch any potential issues (if any).
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c1a36101
...@@ -2175,6 +2175,8 @@ static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol, ...@@ -2175,6 +2175,8 @@ static int snd_hda_spdif_default_get(struct snd_kcontrol *kcontrol,
int idx = kcontrol->private_value; int idx = kcontrol->private_value;
struct hda_spdif_out *spdif; struct hda_spdif_out *spdif;
if (WARN_ON(codec->spdif_out.used <= idx))
return -EINVAL;
mutex_lock(&codec->spdif_mutex); mutex_lock(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx); spdif = snd_array_elem(&codec->spdif_out, idx);
ucontrol->value.iec958.status[0] = spdif->status & 0xff; ucontrol->value.iec958.status[0] = spdif->status & 0xff;
...@@ -2282,6 +2284,8 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol, ...@@ -2282,6 +2284,8 @@ static int snd_hda_spdif_default_put(struct snd_kcontrol *kcontrol,
unsigned short val; unsigned short val;
int change; int change;
if (WARN_ON(codec->spdif_out.used <= idx))
return -EINVAL;
mutex_lock(&codec->spdif_mutex); mutex_lock(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx); spdif = snd_array_elem(&codec->spdif_out, idx);
nid = spdif->nid; nid = spdif->nid;
...@@ -2308,6 +2312,8 @@ static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol, ...@@ -2308,6 +2312,8 @@ static int snd_hda_spdif_out_switch_get(struct snd_kcontrol *kcontrol,
int idx = kcontrol->private_value; int idx = kcontrol->private_value;
struct hda_spdif_out *spdif; struct hda_spdif_out *spdif;
if (WARN_ON(codec->spdif_out.used <= idx))
return -EINVAL;
mutex_lock(&codec->spdif_mutex); mutex_lock(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx); spdif = snd_array_elem(&codec->spdif_out, idx);
ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE; ucontrol->value.integer.value[0] = spdif->ctls & AC_DIG1_ENABLE;
...@@ -2336,6 +2342,8 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol, ...@@ -2336,6 +2342,8 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
unsigned short val; unsigned short val;
int change; int change;
if (WARN_ON(codec->spdif_out.used <= idx))
return -EINVAL;
mutex_lock(&codec->spdif_mutex); mutex_lock(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx); spdif = snd_array_elem(&codec->spdif_out, idx);
nid = spdif->nid; nid = spdif->nid;
...@@ -2483,6 +2491,8 @@ void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx) ...@@ -2483,6 +2491,8 @@ void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx)
{ {
struct hda_spdif_out *spdif; struct hda_spdif_out *spdif;
if (WARN_ON(codec->spdif_out.used <= idx))
return;
mutex_lock(&codec->spdif_mutex); mutex_lock(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx); spdif = snd_array_elem(&codec->spdif_out, idx);
spdif->nid = (u16)-1; spdif->nid = (u16)-1;
...@@ -2503,6 +2513,8 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid) ...@@ -2503,6 +2513,8 @@ void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid)
struct hda_spdif_out *spdif; struct hda_spdif_out *spdif;
unsigned short val; unsigned short val;
if (WARN_ON(codec->spdif_out.used <= idx))
return;
mutex_lock(&codec->spdif_mutex); mutex_lock(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx); spdif = snd_array_elem(&codec->spdif_out, idx);
if (spdif->nid != nid) { if (spdif->nid != nid) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment