]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ALSA: usb-audio: Update US-16x08 EQ/comp shadow state after successful writes
authorCássio Gabriel <cassiogabrielcontato@gmail.com>
Sun, 19 Apr 2026 20:30:32 +0000 (17:30 -0300)
committerTakashi Iwai <tiwai@suse.de>
Mon, 27 Apr 2026 11:44:49 +0000 (13:44 +0200)
snd_us16x08_comp_put() and snd_us16x08_eq_put() update their
software stores before sending the USB write. If the transfer
fails, later get callbacks report a value the hardware never
accepted.

Build the outgoing message from the current store plus the
pending value, then commit the store only after a successful
write.

Fixes: d2bb390a2081 ("ALSA: usb-audio: Tascam US-16x08 DSP mixer quirk")
Cc: stable@vger.kernel.org
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260419-usb-write-error-propagation-v1-4-5a3bd4a673ae@gmail.com
sound/usb/mixer_us16x08.c

index fcf7dfa4aa8450cef659b2233fa45ff407cc6e0a..ebff185cbd2c0e869994615e962b44c5cccbfa1b 100644 (file)
@@ -435,6 +435,7 @@ static int snd_us16x08_comp_put(struct snd_kcontrol *kcontrol,
        int index = ucontrol->id.index;
        char buf[sizeof(comp_msg)];
        int val_idx, val;
+       int threshold, ratio, attack, release, gain, switch_on;
        int err;
 
        val = ucontrol->value.integer.value[0];
@@ -447,36 +448,61 @@ static int snd_us16x08_comp_put(struct snd_kcontrol *kcontrol,
        /* new control value incl. bias*/
        val_idx = elem->head.id - SND_US16X08_ID_COMP_BASE;
 
-       store->val[val_idx][index] = ucontrol->value.integer.value[0];
+       threshold = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD)]
+               [index];
+       ratio = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO)][index];
+       attack = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK)][index];
+       release = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE)]
+               [index];
+       gain = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN)][index];
+       switch_on = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)]
+               [index];
+
+       switch (val_idx) {
+       case COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD):
+               threshold = val;
+               break;
+       case COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO):
+               ratio = val;
+               break;
+       case COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK):
+               attack = val;
+               break;
+       case COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE):
+               release = val;
+               break;
+       case COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN):
+               gain = val;
+               break;
+       case COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH):
+               switch_on = val;
+               break;
+       }
 
        /* prepare compressor URB message from template  */
        memcpy(buf, comp_msg, sizeof(comp_msg));
 
        /* place comp values in message buffer watch bias! */
-       buf[8] = store->val[
-               COMP_STORE_IDX(SND_US16X08_ID_COMP_THRESHOLD)][index]
-               - SND_US16X08_COMP_THRESHOLD_BIAS;
-       buf[11] = ratio_map[store->val[
-               COMP_STORE_IDX(SND_US16X08_ID_COMP_RATIO)][index]];
-       buf[14] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_ATTACK)][index]
-               + SND_US16X08_COMP_ATTACK_BIAS;
-       buf[17] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_RELEASE)][index]
-               + SND_US16X08_COMP_RELEASE_BIAS;
-       buf[20] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_GAIN)][index];
-       buf[26] = store->val[COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)][index];
+       buf[8] = threshold - SND_US16X08_COMP_THRESHOLD_BIAS;
+       buf[11] = ratio_map[ratio];
+       buf[14] = attack + SND_US16X08_COMP_ATTACK_BIAS;
+       buf[17] = release + SND_US16X08_COMP_RELEASE_BIAS;
+       buf[20] = gain;
+       buf[26] = switch_on;
 
        /* place channel selector in message buffer */
        buf[5] = index + 1;
 
        err = snd_us16x08_send_urb(chip, buf, sizeof(comp_msg));
 
-       if (err > 0) {
-               elem->cached |= 1 << index;
-               elem->cache_val[index] = val;
-       } else {
+       if (err < 0) {
                usb_audio_dbg(chip, "Failed to set compressor, err:%d\n", err);
+               return err;
        }
 
+       store->val[val_idx][index] = val;
+       elem->cached |= 1 << index;
+       elem->cache_val[index] = val;
        return 1;
 }
 
@@ -578,11 +604,10 @@ static int snd_us16x08_eq_put(struct snd_kcontrol *kcontrol,
        /* copy URB buffer from EQ template */
        memcpy(buf, eqs_msq, sizeof(eqs_msq));
 
-       store->val[b_idx][p_idx][index] = val;
-       buf[20] = store->val[b_idx][3][index];
-       buf[17] = store->val[b_idx][2][index];
-       buf[14] = store->val[b_idx][1][index];
-       buf[11] = store->val[b_idx][0][index];
+       buf[20] = p_idx == 3 ? val : store->val[b_idx][3][index];
+       buf[17] = p_idx == 2 ? val : store->val[b_idx][2][index];
+       buf[14] = p_idx == 1 ? val : store->val[b_idx][1][index];
+       buf[11] = p_idx == 0 ? val : store->val[b_idx][0][index];
 
        /* place channel index in URB buffer */
        buf[5] = index + 1;
@@ -592,14 +617,15 @@ static int snd_us16x08_eq_put(struct snd_kcontrol *kcontrol,
 
        err = snd_us16x08_send_urb(chip, buf, sizeof(eqs_msq));
 
-       if (err > 0) {
-               /* store new value in EQ band cache */
-               elem->cached |= 1 << index;
-               elem->cache_val[index] = val;
-       } else {
+       if (err < 0) {
                usb_audio_dbg(chip, "Failed to set eq param, err:%d\n", err);
+               return err;
        }
 
+       store->val[b_idx][p_idx][index] = val;
+       /* store new value in EQ band cache */
+       elem->cached |= 1 << index;
+       elem->cache_val[index] = val;
        return 1;
 }