[ALSA] mixart - Check value range in ctl callbacks
Check the value ranges in ctl put callbacks properly. Also fixed some coding style issues around that. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
9cd17cd240
commit
ab2dac2bdc
1 changed files with 83 additions and 41 deletions
|
@ -376,15 +376,27 @@ static int mixart_analog_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
|
||||||
|
|
||||||
mutex_lock(&chip->mgr->mixer_mutex);
|
mutex_lock(&chip->mgr->mixer_mutex);
|
||||||
is_capture = (kcontrol->private_value != 0);
|
is_capture = (kcontrol->private_value != 0);
|
||||||
for(i=0; i<2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
int new_volume = ucontrol->value.integer.value[i];
|
int new_volume = ucontrol->value.integer.value[i];
|
||||||
int* stored_volume = is_capture ? &chip->analog_capture_volume[i] : &chip->analog_playback_volume[i];
|
int *stored_volume = is_capture ?
|
||||||
if(*stored_volume != new_volume) {
|
&chip->analog_capture_volume[i] :
|
||||||
|
&chip->analog_playback_volume[i];
|
||||||
|
if (is_capture) {
|
||||||
|
if (new_volume < MIXART_ANALOG_CAPTURE_LEVEL_MIN ||
|
||||||
|
new_volume > MIXART_ANALOG_CAPTURE_LEVEL_MAX)
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (new_volume < MIXART_ANALOG_PLAYBACK_LEVEL_MIN ||
|
||||||
|
new_volume > MIXART_ANALOG_PLAYBACK_LEVEL_MAX)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (*stored_volume != new_volume) {
|
||||||
*stored_volume = new_volume;
|
*stored_volume = new_volume;
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changed) mixart_update_analog_audio_level(chip, is_capture);
|
if (changed)
|
||||||
|
mixart_update_analog_audio_level(chip, is_capture);
|
||||||
mutex_unlock(&chip->mgr->mixer_mutex);
|
mutex_unlock(&chip->mgr->mixer_mutex);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -421,13 +433,16 @@ static int mixart_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
|
||||||
struct snd_mixart *chip = snd_kcontrol_chip(kcontrol);
|
struct snd_mixart *chip = snd_kcontrol_chip(kcontrol);
|
||||||
int i, changed = 0;
|
int i, changed = 0;
|
||||||
mutex_lock(&chip->mgr->mixer_mutex);
|
mutex_lock(&chip->mgr->mixer_mutex);
|
||||||
for(i=0; i<2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if(chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) {
|
if (chip->analog_playback_active[i] !=
|
||||||
chip->analog_playback_active[i] = ucontrol->value.integer.value[i];
|
ucontrol->value.integer.value[i]) {
|
||||||
|
chip->analog_playback_active[i] =
|
||||||
|
!!ucontrol->value.integer.value[i];
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changed) mixart_update_analog_audio_level(chip, 0); /* update playback levels */
|
if (changed) /* update playback levels */
|
||||||
|
mixart_update_analog_audio_level(chip, 0);
|
||||||
mutex_unlock(&chip->mgr->mixer_mutex);
|
mutex_unlock(&chip->mgr->mixer_mutex);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -843,23 +858,33 @@ static int mixart_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
|
||||||
int* stored_volume;
|
int* stored_volume;
|
||||||
int i;
|
int i;
|
||||||
mutex_lock(&chip->mgr->mixer_mutex);
|
mutex_lock(&chip->mgr->mixer_mutex);
|
||||||
if(is_capture) {
|
if (is_capture) {
|
||||||
if(is_aes) stored_volume = chip->digital_capture_volume[1]; /* AES capture */
|
if (is_aes) /* AES capture */
|
||||||
else stored_volume = chip->digital_capture_volume[0]; /* analog capture */
|
stored_volume = chip->digital_capture_volume[1];
|
||||||
|
else /* analog capture */
|
||||||
|
stored_volume = chip->digital_capture_volume[0];
|
||||||
} else {
|
} else {
|
||||||
snd_assert ( idx < MIXART_PLAYBACK_STREAMS );
|
snd_assert ( idx < MIXART_PLAYBACK_STREAMS );
|
||||||
if(is_aes) stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; /* AES playback */
|
if (is_aes) /* AES playback */
|
||||||
else stored_volume = chip->digital_playback_volume[idx]; /* analog playback */
|
stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx];
|
||||||
|
else /* analog playback */
|
||||||
|
stored_volume = chip->digital_playback_volume[idx];
|
||||||
}
|
}
|
||||||
for(i=0; i<2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if(stored_volume[i] != ucontrol->value.integer.value[i]) {
|
int vol = ucontrol->value.integer.value[i];
|
||||||
stored_volume[i] = ucontrol->value.integer.value[i];
|
if (vol < MIXART_DIGITAL_LEVEL_MIN ||
|
||||||
|
vol > MIXART_DIGITAL_LEVEL_MAX)
|
||||||
|
continue;
|
||||||
|
if (stored_volume[i] != vol) {
|
||||||
|
stored_volume[i] = vol;
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changed) {
|
if (changed) {
|
||||||
if(is_capture) mixart_update_capture_stream_level(chip, is_aes);
|
if (is_capture)
|
||||||
else mixart_update_playback_stream_level(chip, is_aes, idx);
|
mixart_update_capture_stream_level(chip, is_aes);
|
||||||
|
else
|
||||||
|
mixart_update_playback_stream_level(chip, is_aes, idx);
|
||||||
}
|
}
|
||||||
mutex_unlock(&chip->mgr->mixer_mutex);
|
mutex_unlock(&chip->mgr->mixer_mutex);
|
||||||
return changed;
|
return changed;
|
||||||
|
@ -905,14 +930,18 @@ static int mixart_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
|
||||||
snd_assert ( idx < MIXART_PLAYBACK_STREAMS );
|
snd_assert ( idx < MIXART_PLAYBACK_STREAMS );
|
||||||
mutex_lock(&chip->mgr->mixer_mutex);
|
mutex_lock(&chip->mgr->mixer_mutex);
|
||||||
j = idx;
|
j = idx;
|
||||||
if(is_aes) j += MIXART_PLAYBACK_STREAMS;
|
if (is_aes)
|
||||||
for(i=0; i<2; i++) {
|
j += MIXART_PLAYBACK_STREAMS;
|
||||||
if(chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) {
|
for (i = 0; i < 2; i++) {
|
||||||
chip->digital_playback_active[j][i] = ucontrol->value.integer.value[i];
|
if (chip->digital_playback_active[j][i] !=
|
||||||
|
ucontrol->value.integer.value[i]) {
|
||||||
|
chip->digital_playback_active[j][i] =
|
||||||
|
!!ucontrol->value.integer.value[i];
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changed) mixart_update_playback_stream_level(chip, is_aes, idx);
|
if (changed)
|
||||||
|
mixart_update_playback_stream_level(chip, is_aes, idx);
|
||||||
mutex_unlock(&chip->mgr->mixer_mutex);
|
mutex_unlock(&chip->mgr->mixer_mutex);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -975,9 +1004,11 @@ static int mixart_monitor_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
int i;
|
int i;
|
||||||
mutex_lock(&chip->mgr->mixer_mutex);
|
mutex_lock(&chip->mgr->mixer_mutex);
|
||||||
for(i=0; i<2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if(chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) {
|
if (chip->monitoring_volume[i] !=
|
||||||
chip->monitoring_volume[i] = ucontrol->value.integer.value[i];
|
ucontrol->value.integer.value[i]) {
|
||||||
|
chip->monitoring_volume[i] =
|
||||||
|
!!ucontrol->value.integer.value[i];
|
||||||
mixart_update_monitoring(chip, i);
|
mixart_update_monitoring(chip, i);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
@ -1017,24 +1048,35 @@ static int mixart_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
int i;
|
int i;
|
||||||
mutex_lock(&chip->mgr->mixer_mutex);
|
mutex_lock(&chip->mgr->mixer_mutex);
|
||||||
for(i=0; i<2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if(chip->monitoring_active[i] != ucontrol->value.integer.value[i]) {
|
if (chip->monitoring_active[i] !=
|
||||||
chip->monitoring_active[i] = ucontrol->value.integer.value[i];
|
ucontrol->value.integer.value[i]) {
|
||||||
|
chip->monitoring_active[i] =
|
||||||
|
!!ucontrol->value.integer.value[i];
|
||||||
changed |= (1<<i); /* mask 0x01 ans 0x02 */
|
changed |= (1<<i); /* mask 0x01 ans 0x02 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changed) {
|
if (changed) {
|
||||||
/* allocate or release resources for monitoring */
|
/* allocate or release resources for monitoring */
|
||||||
int allocate = chip->monitoring_active[0] || chip->monitoring_active[1];
|
int allocate = chip->monitoring_active[0] ||
|
||||||
if(allocate) {
|
chip->monitoring_active[1];
|
||||||
snd_mixart_add_ref_pipe( chip, MIXART_PCM_ANALOG, 0, 1); /* allocate the playback pipe for monitoring */
|
if (allocate) {
|
||||||
snd_mixart_add_ref_pipe( chip, MIXART_PCM_ANALOG, 1, 1); /* allocate the capture pipe for monitoring */
|
/* allocate the playback pipe for monitoring */
|
||||||
|
snd_mixart_add_ref_pipe(chip, MIXART_PCM_ANALOG, 0, 1);
|
||||||
|
/* allocate the capture pipe for monitoring */
|
||||||
|
snd_mixart_add_ref_pipe(chip, MIXART_PCM_ANALOG, 1, 1);
|
||||||
}
|
}
|
||||||
if(changed & 0x01) mixart_update_monitoring(chip, 0);
|
if (changed & 0x01)
|
||||||
if(changed & 0x02) mixart_update_monitoring(chip, 1);
|
mixart_update_monitoring(chip, 0);
|
||||||
if(!allocate) {
|
if (changed & 0x02)
|
||||||
snd_mixart_kill_ref_pipe( chip->mgr, &chip->pipe_in_ana, 1); /* release the capture pipe for monitoring */
|
mixart_update_monitoring(chip, 1);
|
||||||
snd_mixart_kill_ref_pipe( chip->mgr, &chip->pipe_out_ana, 1); /* release the playback pipe for monitoring */
|
if (!allocate) {
|
||||||
|
/* release the capture pipe for monitoring */
|
||||||
|
snd_mixart_kill_ref_pipe(chip->mgr,
|
||||||
|
&chip->pipe_in_ana, 1);
|
||||||
|
/* release the playback pipe for monitoring */
|
||||||
|
snd_mixart_kill_ref_pipe(chip->mgr,
|
||||||
|
&chip->pipe_out_ana, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue