All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pavel Artemev" <a@pavel.bz>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 2/2] ALSA: usb-audio: add MIXER_STATE_REPUSH quirk flag
Date: Tue, 17 Nov 2026 20:13:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-219579@kernel.org> (raw)
In-Reply-To: <20261117194630.155912-3-a@pavel.bz>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ALSA: usb-audio: clearing master cache bit breaks
  mixer_ctl_feature_get()
- [Medium] ALSA: usb-audio: mixer_ctl_feature_put() drops unchanged
  master ownership
- [Medium] ALSA: usb-audio: snd_usb_mixer_flush_pending() loses pending
  state on error
--

commit 44887f9cb8c6632f7e6e12e06a599b842f0a6231
Author: Pavel Artemev <a@pavel.bz>

ALSA: usb-audio: add MIXER_STATE_REPUSH quirk flag

This commit introduces QUIRK_FLAG_MIXER_STATE_REPUSH to coalesce feature
unit volume and mute writes into deferred bursts and re-push cached values
on PCM stream open and resume.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=221401
Link: https://lore.kernel.org/linux-sound/20261117180728.117915-3-a@pavel.bz

> diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
> index ad96371add1ad..e487ed8dd158d 100644
> --- a/sound/usb/mixer.c
> +++ b/sound/usb/mixer.c
[ ... ]
> @@ -1608,18 +1618,370 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
>  	return 0;
>  }
[ ... ]
> +static void snd_usb_mixer_flush_pending(struct usb_mixer_interface *mixer,
> +					int level)
> +{
[ ... ]
> +		for_each_mixer_elem(list, mixer, id) {
> +			cval = mixer_elem_list_to_info(list);
> +			if (!is_feature_volume_mute_ctl(cval))
> +				continue;
> +			if (cval->control == UAC_FU_VOLUME && cval->cmask &&
> +			    level != FLUSH_TOUCHED) {
> +				bitmap_zero(cval->pending, MAX_CHANNELS + 1);
> +				repush_ctl_cached(cval);
> +				continue;
> +			}
> +			if (cval->control == UAC_FU_MUTE &&
> +			    level == FLUSH_RESUME_STATE) {
> +				bitmap_zero(cval->pending, MAX_CHANNELS + 1);
> +				repush_ctl_cached(cval);
> +				continue;
> +			}
> +			if (!bitmap_empty(cval->pending, MAX_CHANNELS + 1))
> +				flush_ctl_pending(cval);
> +		}
> +	}
> +}

[Severity: Medium]
Does clearing cval->pending before calling repush_ctl_cached() lose
pending writes if snd_usb_set_cur_mix_value() fails?

Unlike flush_ctl_pending(), repush_ctl_cached() only logs an error when a
transfer fails and does not set the bit back in cval->pending.  For a mute
control during FLUSH_RESUME_STATE, a failed write is never retried by a
subsequent FLUSH_TOUCHED or stream-open FLUSH_FULL_STATE because its
pending bit was already cleared.

[ ... ]

> @@ -1632,16 +1994,152 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
>  				return -EINVAL;
>  			val = get_abs_value(cval, val);
[ ... ]
> +			for_each_mixer_elem(ml, cval->head.mixer,
> +					    cval->head.id) {
> +				struct usb_mixer_elem_info *m =
> +					mixer_elem_list_to_info(ml);
> +				bool was_explicit;
> +
> +				if (!is_feature_volume_mute_ctl(m) ||
> +				    m->control != UAC_FU_VOLUME || m->cmask)
> +					continue;
> +				was_explicit = m->master_explicit;
> +				m->master_explicit = false;
> +				if (test_and_clear_bit(0, m->pending)) {
> +					/* an unflushed explicit value never
> +					 * reached the device: derive the
> +					 * master instead of writing it
> +					 */
> +					clear_bit(0, m->cached);
> +					re_push = true;
> +				} else if (was_explicit && have_ch &&
> +					   test_bit(0, m->cached) &&
> +					   m->cache_val[0] != ch_max) {
> +					/* a flushed explicit value that
> +					 * disagrees with the channels:
> +					 * the device master is stale
> +					 * until something re-derives it
> +					 */
> +					clear_bit(0, m->cached);
> +					re_push = true;
> +				}
> +			}

[Severity: Medium]
Can clearing bit 0 of m->cached here break mixer_ctl_feature_get() on the
master control before the next flush completes?

mixer_ctl_feature_get() calls snd_usb_get_cur_mix_value(cval, 0, 0, &val).
While bit 0 of m->cached is clear (during the 30 ms flush window, or for
the entire duration of runtime suspend because snd_usb_mixer_flush_pending()
returns early when MIXER_FLUSH_SUSPENDED is set), reading the master
control either fails with -ENXIO when m->get_cur_broken is set or issues a
USB GET_CUR readback when it is not.  That readback wakes a
runtime-suspended device and re-sets bit 0 of m->cached; if the device
returns m->max while ch_max == m->max, snd_usb_mixer_flush_pending() will
then hit the raw-max skip and omit writing the derived master.

> +			if (re_push) {
> +				set_bit(MIXER_FLUSH_FULL,
> +					&cval->head.mixer->flush_flags);
> +				mixer_arm_flush(cval->head.mixer);
> +			}
> +		}
>  	} else {
>  		/* master channel */
> +		if (deferred && !test_bit(0, cval->cached)) {
[ ... ]
> +		}
>  		err = snd_usb_get_cur_mix_value(cval, 0, 0, &oval);
>  		if (err < 0)
>  			return filter_error(cval, err);
> @@ -1650,9 +2148,25 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
>  			return -EINVAL;
>  		val = get_abs_value(cval, val);
>  		if (val != oval) {
> -			err = snd_usb_set_cur_mix_value(cval, 0, 0, val);
> -			if (err < 0)
> -				return filter_error(cval, err);
> +			if (deferred) {
> +				/* record only; one flush writes the whole
> +				 * unit in a single burst.  Read-only
> +				 * masters keep the direct-path behaviour:
> +				 * no write, no cache update.
> +				 */
> +				if (!mixer_ch_readonly(cval, 0)) {
> +					set_bit(0, cval->cached);
> +					cval->cache_val[0] = val;
> +					set_bit(0, cval->pending);
> +					if (cval->control == UAC_FU_VOLUME)
> +						cval->master_explicit = true;
> +					mixer_arm_flush(cval->head.mixer);
> +				}
> +			} else {

[Severity: Medium]
Does gating cval->master_explicit = true on val != oval lose master
ownership when an explicit master write matches the pre-flush master cache?

When user space writes a new value to the volume channels while
cval->master_explicit is false, cval->cache_val[0] on the master control
keeps its previous value until snd_usb_mixer_flush_pending() runs.  If user
space then writes that previous value to the master control before the
flush fires (or while the device is runtime-suspended), val == oval holds,
so cval->master_explicit and bit 0 of cval->pending remain unset and the
flush overwrites the master with the derived channel value.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117194630.155912-1-a@pavel.bz?part=2

  reply	other threads:[~2026-11-17 20:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 19:46 [RFC PATCH v7 0/2] ALSA: usb-audio: working hardware volume for XiiSound headsets (040b:0897) Pavel Artemev
2026-11-17 19:46 ` [PATCH 1/2] ALSA: usb-audio: drive XiiSound playback volume instead of skipping it Pavel Artemev
2026-11-17 19:46 ` [PATCH 2/2] ALSA: usb-audio: add MIXER_STATE_REPUSH quirk flag Pavel Artemev
2026-11-17 20:13   ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-17 18:07 [RFC PATCH v6 0/2] ALSA: usb-audio: working hardware volume for XiiSound headsets (040b:0897) Pavel Artemev
2026-11-17 18:07 ` [PATCH 2/2] ALSA: usb-audio: add MIXER_STATE_REPUSH quirk flag Pavel Artemev
2026-11-17 18:40   ` sashiko-bot
2026-11-17 14:33 [RFC PATCH v5 0/2] ALSA: usb-audio: working hardware volume for XiiSound headsets (040b:0897) Pavel Artemev
2026-11-17 14:33 ` [PATCH 2/2] ALSA: usb-audio: add MIXER_STATE_REPUSH quirk flag Pavel Artemev
2026-11-17 15:04   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-219579@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a@pavel.bz \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.