From: sashiko-bot@kernel.org
To: "Pavel Artemev" <a@pavel.bz>
Cc: linux-sound@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] ALSA: usb-audio: drive XiiSound playback volume instead of skipping it
Date: Mon, 16 Nov 2026 15:54:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-217317@kernel.org> (raw)
In-Reply-To: <20261116153521.188570-2-a@pavel.bz>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ALSA: usb-audio: init_volume_max quirk ignores deferred range
init
- [Medium] ALSA: usb-audio: 32-bit BIT() overflow in
snd_usb_mixer_init_volume_max()
--
commit 2df8ef85ac853457efaa66341d89d1aca5a40143
Author: Pavel Artemev <a@pavel.bz>
ALSA: usb-audio: drive XiiSound playback volume instead of skipping it
This commit replaces the XiiSound (040b:0897) playback feature unit skip
quirk with linear volume quirk flags and a new QUIRK_FLAG_MIXER_INIT_VOLUME_MAX
flag that initializes feature unit volume controls to their maximum value at
mixer creation.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=221401
> diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
> index 4c7d68311f204..95877685b7f17 100644
> --- a/sound/usb/mixer_quirks.c
> +++ b/sound/usb/mixer_quirks.c
[ ... ]
> @@ -5218,6 +5159,41 @@ static void snd_fix_plt_name(struct snd_usb_audio *chip,
> usb_audio_dbg(chip, "something wrong in kctl name %s\n", id->name);
> }
>
> +/*
> + * A Feature Unit volume channel left at the minimum value silences its
> + * audio path on some devices. Write the maximum volume to all channels
> + * once at mixer creation, so that the audio path is open; the controls
> + * remain writable and the hardware volume operates normally afterwards.
> + */
> +static void snd_usb_mixer_init_volume_max(struct usb_mixer_interface *mixer,
> + struct usb_mixer_elem_info *cval)
> +{
> + int i, idx, err;
> +
> + usb_audio_info(mixer->chip, "applying init volume max quirk\n");
> +
> + if (!cval->cmask) {
> + /* master channel */
> + err = snd_usb_set_cur_mix_value(cval, 0, 0, cval->max);
> + if (err < 0)
> + usb_audio_dbg(mixer->chip, "cannot init control %d ch 0 to max: %d\n",
> + cval->control, err);
> + return;
> + }
> +
> + idx = 0;
> + for (i = 0; i < MAX_CHANNELS; i++) {
> + if (!(cval->cmask & BIT(i)))
> + continue;
> + /* per-channel writes apply independently; keep going on error */
> + err = snd_usb_set_cur_mix_value(cval, i + 1, idx, cval->max);
> + if (err < 0)
> + usb_audio_dbg(mixer->chip, "cannot init control %d ch %d to max: %d\n",
> + cval->control, i + 1, err);
> + idx++;
> + }
> +}
[Severity: Medium]
Does BIT(i) overflow on 32-bit architectures when i reaches 32?
MAX_CHANNELS is 64 and cval->cmask is a u64, whereas BIT(i) uses unsigned
long. On 32-bit kernels, shifting by i >= 32 is undefined behavior and, on
architectures that mask shift counts modulo 32, matches bits 0..31 a second
time for i = 32..63, sending UAC_SET_CUR requests for non-existent channels
33..64 and writing extra entries into cval->cached and cval->cache_val[].
Using BIT_ULL(i) avoids the 32-bit shift overflow.
> @@ -5265,6 +5241,11 @@ void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer,
> if (cval->control == UAC_FU_VOLUME && strstr(kctl->id.name, "Capture"))
> snd_usb_mixer_fu_quirk_linear_scale(mixer, cval, kctl);
>
> + /* devices that silence a channel left at the minimum value */
> + if (mixer->chip->quirk_flags & QUIRK_FLAG_MIXER_INIT_VOLUME_MAX)
> + if (cval->control == UAC_FU_VOLUME)
> + snd_usb_mixer_init_volume_max(mixer, cval);
[Severity: Medium]
What happens when get_min_max_with_quirks() returns -EAGAIN during
__build_feature_ctl() and defers range initialization?
__build_feature_ctl() continues past -EAGAIN with cval->initialized == 0 and
the failsafe cval->max == 1, so snd_usb_mixer_init_volume_max() writes 1 to
every channel and marks cval->cached. When mixer_ctl_feature_info() later
runs get_min_max_with_quirks() to finish initialization, init_cur_mix_raw()
either overwrites all channels with cval->min without
snd_usb_mixer_init_volume_max() running again, or skips channels already
marked in cval->cached and leaves their cache_val[] entries stuck at 1.
Even when probe-time range discovery succeeds on a device with broken
GET_CUR, init_cur_mix_raw() first writes cval->min to every channel before
snd_usb_mixer_init_volume_max() writes cval->max, so if the first write
lands and the second is dropped, the channel and cache remain at cval->min.
Handling QUIRK_FLAG_MIXER_INIT_VOLUME_MAX directly in init_cur_mix_raw() (initializing to cval->max instead of cval->min, and across all channels)
would cover deferred initialization and avoid the initial cval->min write.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116153521.188570-1-a@pavel.bz?part=1
next prev parent reply other threads:[~2026-11-16 15:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 15:35 [RFC PATCH 0/2] ALSA: usb-audio: working hardware volume for XiiSound headsets (040b:0897) Pavel Artemev
2026-11-16 15:35 ` [RFC PATCH 1/2] ALSA: usb-audio: drive XiiSound playback volume instead of skipping it Pavel Artemev
2026-11-16 15:54 ` sashiko-bot [this message]
2026-11-16 15:35 ` [RFC PATCH 2/2] ALSA: usb-audio: add MIXER_STATE_REPUSH quirk flag Pavel Artemev
2026-11-16 15:58 ` 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-217317@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox