From: Rong Zhang <i@rong.moe>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: Rong Zhang <i@rong.moe>, Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Cryolitia PukNgae <cryolitia@uniontech.com>,
Arun Raghavan <arunr@valvesoftware.com>,
linux-sound@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, Icenowy Zheng <uwu@icenowy.me>
Subject: [PATCH 2/9] ALSA: usb-audio: Add helper function for volume range checks
Date: Mon, 2 Mar 2026 05:37:18 +0800 [thread overview]
Message-ID: <20260301213726.428505-3-i@rong.moe> (raw)
In-Reply-To: <20260301213726.428505-1-i@rong.moe>
When a potentially insane volume range is found, the volume control
parameters will be printed in WARN level instead of DEBUG level.
Currently, it's done by emitting a open-coded usb_audio_warn() in the
corresponding check.
The following changes are about to add more checks against volumen
ranges. As the first step, extract the current check logic into a helper
function to improve readability.
No functional change intended.
Signed-off-by: Rong Zhang <i@rong.moe>
---
sound/usb/mixer.c | 43 +++++++++++++++++++++++++++----------------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index df0d3df9c7ece..f52ca0d7e6653 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1660,6 +1660,27 @@ static const struct usb_feature_control_info *get_feature_control_info(int contr
return NULL;
}
+static bool check_insane_volume_range(struct usb_mixer_interface *mixer,
+ struct snd_kcontrol *kctl,
+ struct usb_mixer_elem_info *cval)
+{
+ int range = (cval->max - cval->min) / cval->res;
+
+ /*
+ * Are there devices with volume range more than 255? I use a bit more
+ * to be sure. 384 is a resolution magic number found on Logitech
+ * devices. It will definitively catch all buggy Logitech devices.
+ */
+ if (range > 384) {
+ usb_audio_warn(mixer->chip,
+ "Warning! Unlikely big volume range (=%u), cval->res is probably wrong.",
+ range);
+ return true;
+ }
+
+ return false;
+}
+
static void __build_feature_ctl(struct usb_mixer_interface *mixer,
const struct usbmix_name_map *imap,
unsigned int ctl_mask, int control,
@@ -1673,7 +1694,6 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
struct snd_kcontrol *kctl;
struct usb_mixer_elem_info *cval;
const struct usbmix_name_map *map;
- unsigned int range;
if (control == UAC_FU_GRAPHIC_EQUALIZER) {
/* FIXME: not supported yet */
@@ -1811,25 +1831,16 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
snd_usb_mixer_fu_apply_quirk(mixer, cval, unitid, kctl);
- range = (cval->max - cval->min) / cval->res;
- /*
- * Are there devices with volume range more than 255? I use a bit more
- * to be sure. 384 is a resolution magic number found on Logitech
- * devices. It will definitively catch all buggy Logitech devices.
- */
- if (range > 384) {
- usb_audio_warn(mixer->chip,
- "Warning! Unlikely big volume range (=%u), cval->res is probably wrong.",
- range);
- usb_audio_warn(mixer->chip,
- "[%d] FU [%s] ch = %d, val = %d/%d/%d",
+ if (check_insane_volume_range(mixer, kctl, cval)) {
+ usb_audio_warn(mixer->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
cval->head.id, kctl->id.name, cval->channels,
cval->min, cval->max, cval->res);
+ } else {
+ usb_audio_dbg(mixer->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
+ cval->head.id, kctl->id.name, cval->channels,
+ cval->min, cval->max, cval->res);
}
- usb_audio_dbg(mixer->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
- cval->head.id, kctl->id.name, cval->channels,
- cval->min, cval->max, cval->res);
snd_usb_mixer_add_control(&cval->head, kctl);
}
--
2.51.0
next prev parent reply other threads:[~2026-03-01 21:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-01 21:37 [PATCH 0/9] ALSA: usb-audio: Add quirks for linear volume devices and deconflict VID Rong Zhang
2026-03-01 21:37 ` [PATCH 1/9] Revert "ALSA: usb: Increase volume range that triggers a warning" Rong Zhang
2026-03-01 21:37 ` Rong Zhang [this message]
2026-03-01 21:37 ` [PATCH 3/9] ALSA: usb-audio: Improve volume range checks Rong Zhang
2026-03-01 21:37 ` [PATCH 4/9] ALSA: usb-audio: Support string-descriptor-based quirk table entry Rong Zhang
2026-03-02 9:54 ` Takashi Iwai
2026-03-02 12:31 ` Rong Zhang
2026-03-05 6:13 ` Terry Junge
2026-03-05 12:06 ` Takashi Iwai
2026-03-05 12:24 ` Rong Zhang
2026-03-01 21:37 ` [PATCH 5/9] ALSA: usb-audio: Deconflict VID between Focusrite Novation & MV-SILICON Rong Zhang
2026-03-01 21:37 ` [PATCH 6/9] ALSA: doc: Add doc for QUIRK_FLAG_SKIP_IFACE_SETUP of snd-usb-audio Rong Zhang
2026-03-01 21:37 ` [PATCH 7/9] ALSA: usb-audio: Add QUIRK_FLAG_MIXER_{PLAYBACK,CAPTURE}_LINEAR_VOL Rong Zhang
2026-03-01 21:37 ` [PATCH 8/9] ALSA: usb-audio: Add linear volume quirk for Hotone Audio Pulze Mini Rong Zhang
2026-03-01 21:37 ` [PATCH 9/9] ALSA: usb-audio: Apply linear volume quirk on MV-SILICON devices Rong Zhang
2026-03-02 9:59 ` [PATCH 0/9] ALSA: usb-audio: Add quirks for linear volume devices and deconflict VID Takashi Iwai
2026-03-02 12:40 ` Rong Zhang
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=20260301213726.428505-3-i@rong.moe \
--to=i@rong.moe \
--cc=arunr@valvesoftware.com \
--cc=corbet@lwn.net \
--cc=cryolitia@uniontech.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=skhan@linuxfoundation.org \
--cc=tiwai@suse.com \
--cc=uwu@icenowy.me \
/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