Commit 9cd17cd2 authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] ice1724 - Check value ranges in ctl callbacks

Check the value ranges in ctl put callbacks properly.
Also fixed the wrong access type to enum elements in aureon.c.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 68ea7b2f
...@@ -205,7 +205,7 @@ static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol, ...@@ -205,7 +205,7 @@ static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
ucontrol->value.integer.value[0] = ice->spec.aureon.pca9554_out; ucontrol->value.enumerated.item[0] = ice->spec.aureon.pca9554_out;
return 0; return 0;
} }
...@@ -216,10 +216,11 @@ static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol, ...@@ -216,10 +216,11 @@ static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol,
unsigned char oval, nval; unsigned char oval, nval;
int change; int change;
nval = ucontrol->value.enumerated.item[0];
if (nval >= 3)
return -EINVAL;
snd_ice1712_save_gpio_status(ice); snd_ice1712_save_gpio_status(ice);
oval = ice->spec.aureon.pca9554_out; oval = ice->spec.aureon.pca9554_out;
nval = ucontrol->value.integer.value[0];
if ((change = (oval != nval))) { if ((change = (oval != nval))) {
aureon_pca9554_write(ice, PCA9554_OUT, nval); aureon_pca9554_write(ice, PCA9554_OUT, nval);
ice->spec.aureon.pca9554_out = nval; ice->spec.aureon.pca9554_out = nval;
...@@ -757,10 +758,13 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ ...@@ -757,10 +758,13 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
snd_ice1712_save_gpio_status(ice); snd_ice1712_save_gpio_status(ice);
for (ch = 0; ch < 2; ch++) { for (ch = 0; ch < 2; ch++) {
if (ucontrol->value.integer.value[ch] != ice->spec.aureon.master[ch]) { unsigned int vol = ucontrol->value.integer.value[ch];
if (vol > WM_VOL_MAX)
continue;
vol |= ice->spec.aureon.master[ch] & WM_VOL_MUTE;
if (vol != ice->spec.aureon.master[ch]) {
int dac; int dac;
ice->spec.aureon.master[ch] &= WM_VOL_MUTE; ice->spec.aureon.master[ch] = vol;
ice->spec.aureon.master[ch] |= ucontrol->value.integer.value[ch];
for (dac = 0; dac < ice->num_total_dacs; dac += 2) for (dac = 0; dac < ice->num_total_dacs; dac += 2)
wm_set_vol(ice, WM_DAC_ATTEN + dac + ch, wm_set_vol(ice, WM_DAC_ATTEN + dac + ch,
ice->spec.aureon.vol[dac + ch], ice->spec.aureon.vol[dac + ch],
...@@ -807,10 +811,13 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ...@@ -807,10 +811,13 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *
ofs = kcontrol->private_value & 0xff; ofs = kcontrol->private_value & 0xff;
snd_ice1712_save_gpio_status(ice); snd_ice1712_save_gpio_status(ice);
for (i = 0; i < voices; i++) { for (i = 0; i < voices; i++) {
idx = WM_DAC_ATTEN + ofs + i; unsigned int vol = ucontrol->value.integer.value[i];
if (ucontrol->value.integer.value[i] != ice->spec.aureon.vol[ofs+i]) { if (vol > 0x7f)
ice->spec.aureon.vol[ofs+i] &= WM_VOL_MUTE; continue;
ice->spec.aureon.vol[ofs+i] |= ucontrol->value.integer.value[i]; vol |= ice->spec.aureon.vol[ofs+i];
if (vol != ice->spec.aureon.vol[ofs+i]) {
ice->spec.aureon.vol[ofs+i] = vol;
idx = WM_DAC_ATTEN + ofs + i;
wm_set_vol(ice, idx, ice->spec.aureon.vol[ofs+i], wm_set_vol(ice, idx, ice->spec.aureon.vol[ofs+i],
ice->spec.aureon.master[i]); ice->spec.aureon.master[i]);
change = 1; change = 1;
...@@ -940,8 +947,10 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val ...@@ -940,8 +947,10 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
unsigned short ovol, nvol; unsigned short ovol, nvol;
int change = 0; int change = 0;
snd_ice1712_save_gpio_status(ice);
nvol = ucontrol->value.integer.value[0]; nvol = ucontrol->value.integer.value[0];
if (nvol > PCM_RES)
return -EINVAL;
snd_ice1712_save_gpio_status(ice);
nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff; nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff;
ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
if (ovol != nvol) { if (ovol != nvol) {
...@@ -1031,7 +1040,7 @@ static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val ...@@ -1031,7 +1040,7 @@ static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
snd_ice1712_save_gpio_status(ice); snd_ice1712_save_gpio_status(ice);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
idx = WM_ADC_GAIN + i; idx = WM_ADC_GAIN + i;
nvol = ucontrol->value.integer.value[i]; nvol = ucontrol->value.integer.value[i] & 0x1f;
ovol = wm_get(ice, idx); ovol = wm_get(ice, idx);
if ((ovol & 0x1f) != nvol) { if ((ovol & 0x1f) != nvol) {
wm_put(ice, idx, nvol | (ovol & ~0x1f)); wm_put(ice, idx, nvol | (ovol & ~0x1f));
......
...@@ -326,10 +326,13 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ ...@@ -326,10 +326,13 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
snd_ice1712_save_gpio_status(ice); snd_ice1712_save_gpio_status(ice);
for (ch = 0; ch < 2; ch++) { for (ch = 0; ch < 2; ch++) {
if (ucontrol->value.integer.value[ch] != ice->spec.phase28.master[ch]) { unsigned int vol = ucontrol->value.integer.value[ch];
if (vol > WM_VOL_MAX)
continue;
vol |= ice->spec.phase28.master[ch] & WM_VOL_MUTE;
if (vol != ice->spec.phase28.master[ch]) {
int dac; int dac;
ice->spec.phase28.master[ch] &= WM_VOL_MUTE; ice->spec.phase28.master[ch] = vol;
ice->spec.phase28.master[ch] |= ucontrol->value.integer.value[ch];
for (dac = 0; dac < ice->num_total_dacs; dac += 2) for (dac = 0; dac < ice->num_total_dacs; dac += 2)
wm_set_vol(ice, WM_DAC_ATTEN + dac + ch, wm_set_vol(ice, WM_DAC_ATTEN + dac + ch,
ice->spec.phase28.vol[dac + ch], ice->spec.phase28.vol[dac + ch],
...@@ -462,10 +465,14 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ...@@ -462,10 +465,14 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *
ofs = kcontrol->private_value & 0xff; ofs = kcontrol->private_value & 0xff;
snd_ice1712_save_gpio_status(ice); snd_ice1712_save_gpio_status(ice);
for (i = 0; i < voices; i++) { for (i = 0; i < voices; i++) {
idx = WM_DAC_ATTEN + ofs + i; unsigned int vol;
if (ucontrol->value.integer.value[i] != ice->spec.phase28.vol[ofs+i]) { vol = ucontrol->value.integer.value[i];
ice->spec.phase28.vol[ofs+i] &= WM_VOL_MUTE; if (vol > 0x7f)
ice->spec.phase28.vol[ofs+i] |= ucontrol->value.integer.value[i]; continue;
vol |= ice->spec.phase28.vol[ofs+i] & WM_VOL_MUTE;
if (vol != ice->spec.phase28.vol[ofs+i]) {
ice->spec.phase28.vol[ofs+i] = vol;
idx = WM_DAC_ATTEN + ofs + i;
wm_set_vol(ice, idx, ice->spec.phase28.vol[ofs+i], wm_set_vol(ice, idx, ice->spec.phase28.vol[ofs+i],
ice->spec.phase28.master[i]); ice->spec.phase28.master[i]);
change = 1; change = 1;
...@@ -595,8 +602,10 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val ...@@ -595,8 +602,10 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
unsigned short ovol, nvol; unsigned short ovol, nvol;
int change = 0; int change = 0;
snd_ice1712_save_gpio_status(ice);
nvol = ucontrol->value.integer.value[0]; nvol = ucontrol->value.integer.value[0];
if (nvol > PCM_RES)
return -EINVAL;
snd_ice1712_save_gpio_status(ice);
nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff; nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff;
ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
if (ovol != nvol) { if (ovol != nvol) {
......
...@@ -241,7 +241,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el ...@@ -241,7 +241,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
reg = STAC946X_MIC_L_VOLUME + i; reg = STAC946X_MIC_L_VOLUME + i;
nvol = ucontrol->value.integer.value[i]; nvol = ucontrol->value.integer.value[i] & 0x0f;
ovol = 0x0f - stac9460_get(ice, reg); ovol = 0x0f - stac9460_get(ice, reg);
change = ((ovol & 0x0f) != nvol); change = ((ovol & 0x0f) != nvol);
if (change) if (change)
......
...@@ -178,7 +178,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, ...@@ -178,7 +178,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
if (kcontrol->private_value) { if (kcontrol->private_value) {
idx = STAC946X_MASTER_VOLUME; idx = STAC946X_MASTER_VOLUME;
nvol = ucontrol->value.integer.value[0]; nvol = ucontrol->value.integer.value[0] & 0x7f;
tmp = stac9460_get(ice, idx); tmp = stac9460_get(ice, idx);
ovol = 0x7f - (tmp & 0x7f); ovol = 0x7f - (tmp & 0x7f);
change = (ovol != nvol); change = (ovol != nvol);
...@@ -189,7 +189,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, ...@@ -189,7 +189,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
} else { } else {
id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
idx = id + STAC946X_LF_VOLUME; idx = id + STAC946X_LF_VOLUME;
nvol = ucontrol->value.integer.value[0]; nvol = ucontrol->value.integer.value[0] & 0x7f;
if (id < 6) if (id < 6)
tmp = stac9460_get(ice, idx); tmp = stac9460_get(ice, idx);
else else
...@@ -317,7 +317,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, ...@@ -317,7 +317,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
if (id == 0) { if (id == 0) {
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
reg = STAC946X_MIC_L_VOLUME + i; reg = STAC946X_MIC_L_VOLUME + i;
nvol = ucontrol->value.integer.value[i]; nvol = ucontrol->value.integer.value[i] & 0x0f;
ovol = 0x0f - stac9460_get(ice, reg); ovol = 0x0f - stac9460_get(ice, reg);
change = ((ovol & 0x0f) != nvol); change = ((ovol & 0x0f) != nvol);
if (change) if (change)
...@@ -327,7 +327,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, ...@@ -327,7 +327,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
} else { } else {
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
reg = STAC946X_MIC_L_VOLUME + i; reg = STAC946X_MIC_L_VOLUME + i;
nvol = ucontrol->value.integer.value[i]; nvol = ucontrol->value.integer.value[i] & 0x0f;
ovol = 0x0f - stac9460_2_get(ice, reg); ovol = 0x0f - stac9460_2_get(ice, reg);
change = ((ovol & 0x0f) != nvol); change = ((ovol & 0x0f) != nvol);
if (change) if (change)
......
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