Commit 9b5ddea9 authored by Geoffrey D. Bennett's avatar Geoffrey D. Bennett Committed by Takashi Iwai

ALSA: usb-audio: scarlett2: Fix data_mutex lock

The private->vol_updated flag was being checked outside of the
mutex_lock/unlock() of private->data_mutex leading to the volume data
being fetched twice from the device unnecessarily or old volume data
being returned.

Update scarlett2_*_ctl_get() and include the private->vol_updated flag
check inside the critical region.
Signed-off-by: default avatarGeoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/20210620164643.GA9216@m.b4.vuSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 3eeb2a19
...@@ -1153,11 +1153,10 @@ static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl, ...@@ -1153,11 +1153,10 @@ static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
struct usb_mixer_interface *mixer = elem->head.mixer; struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data; struct scarlett2_data *private = mixer->private_data;
if (private->vol_updated) {
mutex_lock(&private->data_mutex); mutex_lock(&private->data_mutex);
if (private->vol_updated)
scarlett2_update_volumes(mixer); scarlett2_update_volumes(mixer);
mutex_unlock(&private->data_mutex); mutex_unlock(&private->data_mutex);
}
ucontrol->value.integer.value[0] = private->master_vol; ucontrol->value.integer.value[0] = private->master_vol;
return 0; return 0;
...@@ -1171,11 +1170,10 @@ static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl, ...@@ -1171,11 +1170,10 @@ static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl,
struct scarlett2_data *private = mixer->private_data; struct scarlett2_data *private = mixer->private_data;
int index = elem->control; int index = elem->control;
if (private->vol_updated) {
mutex_lock(&private->data_mutex); mutex_lock(&private->data_mutex);
if (private->vol_updated)
scarlett2_update_volumes(mixer); scarlett2_update_volumes(mixer);
mutex_unlock(&private->data_mutex); mutex_unlock(&private->data_mutex);
}
ucontrol->value.integer.value[0] = private->vol[index]; ucontrol->value.integer.value[0] = private->vol[index];
return 0; return 0;
...@@ -1439,11 +1437,10 @@ static int scarlett2_dim_mute_ctl_get(struct snd_kcontrol *kctl, ...@@ -1439,11 +1437,10 @@ static int scarlett2_dim_mute_ctl_get(struct snd_kcontrol *kctl,
struct usb_mixer_interface *mixer = elem->head.mixer; struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data; struct scarlett2_data *private = mixer->private_data;
if (private->vol_updated) {
mutex_lock(&private->data_mutex); mutex_lock(&private->data_mutex);
if (private->vol_updated)
scarlett2_update_volumes(mixer); scarlett2_update_volumes(mixer);
mutex_unlock(&private->data_mutex); mutex_unlock(&private->data_mutex);
}
ucontrol->value.enumerated.item[0] = private->dim_mute[elem->control]; ucontrol->value.enumerated.item[0] = private->dim_mute[elem->control];
return 0; return 0;
......
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