diff options
| author | Rong Zhang <i@rong.moe> | 2026-03-03 22:47:57 +0300 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2026-03-04 14:05:57 +0300 |
| commit | 1060dbbbb2f260e4755dbd8d2f53f5a1894397d8 (patch) | |
| tree | 31723156ef1a6830212aa4ac512886d67ce2e6ce | |
| parent | 41d78cb724f4b40b7548af420ccfe524b14023bb (diff) | |
| download | linux-1060dbbbb2f260e4755dbd8d2f53f5a1894397d8.tar.xz | |
ALSA: usb-audio: Add helper function for volume range checks
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260303194805.266158-3-i@rong.moe
| -rw-r--r-- | sound/usb/mixer.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index df0d3df9c7ec..f52ca0d7e665 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); } |
