Skip to content

Commit 14a2956

Browse files
ossilatortiwai
authored andcommitted
ALSA: emu10k1: fix error handling in snd_audigy_i2c_volume_put()
Check all inputs before changing anything, and return the right error code in case of failure. Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Link: https://lore.kernel.org/r/20230422161021.1144026-1-oswald.buddenhagen@gmx.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent dad1730 commit 14a2956

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

sound/pci/emu10k1/emumixer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol,
10061006
{
10071007
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
10081008
unsigned int ogain;
1009-
unsigned int ngain;
1009+
unsigned int ngain0, ngain1;
10101010
unsigned int source_id;
10111011
int change = 0;
10121012

@@ -1015,24 +1015,24 @@ static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol,
10151015
/* capture_source: uinfo->value.enumerated.items = 2 */
10161016
if (source_id >= 2)
10171017
return -EINVAL;
1018+
ngain0 = ucontrol->value.integer.value[0];
1019+
ngain1 = ucontrol->value.integer.value[1];
1020+
if (ngain0 > 0xff)
1021+
return -EINVAL;
1022+
if (ngain1 > 0xff)
1023+
return -EINVAL;
10181024
ogain = emu->i2c_capture_volume[source_id][0]; /* Left */
1019-
ngain = ucontrol->value.integer.value[0];
1020-
if (ngain > 0xff)
1021-
return 0;
1022-
if (ogain != ngain) {
1025+
if (ogain != ngain0) {
10231026
if (emu->i2c_capture_source == source_id)
1024-
snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) );
1025-
emu->i2c_capture_volume[source_id][0] = ngain;
1027+
snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ngain0);
1028+
emu->i2c_capture_volume[source_id][0] = ngain0;
10261029
change = 1;
10271030
}
10281031
ogain = emu->i2c_capture_volume[source_id][1]; /* Right */
1029-
ngain = ucontrol->value.integer.value[1];
1030-
if (ngain > 0xff)
1031-
return 0;
1032-
if (ogain != ngain) {
1032+
if (ogain != ngain1) {
10331033
if (emu->i2c_capture_source == source_id)
1034-
snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
1035-
emu->i2c_capture_volume[source_id][1] = ngain;
1034+
snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ngain1);
1035+
emu->i2c_capture_volume[source_id][1] = ngain1;
10361036
change = 1;
10371037
}
10381038

0 commit comments

Comments
 (0)