From nobody Mon Jun 15 14:00:02 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E62B9175A76; Fri, 10 Apr 2026 17:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843370; cv=pass; b=E99JEev3hrdMyFhIT2YlhESVU0OA3Nco0pri9tcaVtaKQ2GWHmwWBL66c/DAZPBj3lEcamx4i/K/Bh+plPAECVtgKYgEZTumuJIfjav1dcohifVg1pzpjckLh7HSJldkB4CsruswNeSQ05Y6sd+1pQZWke0wAw47wGp6bR+ncgc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843370; c=relaxed/simple; bh=CZYQBruP9KBIyf/fAQRIHn3lD9K8Fg7SaTUiHFP28ZY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l2ka3igT9+DBj+FyqSY1GJwobWvd9iIXhlE3mii0S2TIl4pzgrtKi73Vl6L4WJd94+7u9pQv3SFXHzVYS3a/NRH6kegLfrszQE2kSc+tdvpu6DcExt8xditDMLM0B+BcMlRWzGhxcM10mY3XSjj3gEW7aUKU1R1afOa3xFT4Vlw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=Qab+SCIY; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="Qab+SCIY" ARC-Seal: i=1; a=rsa-sha256; t=1775843363; cv=none; d=zohomail.com; s=zohoarc; b=idltcXz3m4rIGO/oKtStVIBExb3sz0g8gM+5fcwVI9f8GFiGfJlgOWpXYn/uRFlD1gngCJM4mKp7Z4caEz4fTlvWdlPePgWXyxuUfKfzab66FsjWXolq5yCi0uOmIRy0tSX4lHjd3ki+y442gW6feVC/ukHcZ8zBlRGzKRl6wyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775843363; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=ywzL4TYUTBgPH4OTEZpWdrhMm0aJuIfEOysKOGlQRc0=; b=WohfUQTM78SY7ev3oywvlwE7y0C66gXMlsGvbBkwoK4pLWvuom25W7viGuQFd3OONiV0pJcda/jSQJJHLJJor7ctZhn1XjhzuDCM+t9RCEZdkKd8bYb1hUgNDnr81G2qNNJSbpAPtsUAZpJrtCpnFa9FB/dcxPuOqg2NIz+tgFA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1775843363; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=ywzL4TYUTBgPH4OTEZpWdrhMm0aJuIfEOysKOGlQRc0=; b=Qab+SCIYNMLGwnedVE5Y0vDj++JBYcgGQUi+29EEQV/DHddEkHG8Df+6Z873w3RH /HU/uNdkAjUwrKl0WmQT9l6CdhRQmSJtMBoN3Rd5CVfh9eqvbK/4J5n0AVNVV4Xua+r 2HleIDtwzBZyLHmEglhyENDVsfPKO7YZ4QOquIQax6AcGNlIdLlNqzvJ3f7VYJufKpo OMUBwXCSF2U3VNrqrryOyY/Y999lmxU+r1sG6K8JxvYkXc6j+FYdaHatVxD4upZ+77v lVfLoq0zpWjLEaVvgk+Xq9BeftML6qRvnalOX5yrOh+UpSxsyPoz4RNXJ1LUf9wxgCi L/gzW2G0dw== Received: by mx.zohomail.com with SMTPS id 1775843362450723.2142062526651; Fri, 10 Apr 2026 10:49:22 -0700 (PDT) From: Rong Zhang Date: Sat, 11 Apr 2026 01:49:02 +0800 Subject: [PATCH 1/3] ALSA: usb-audio: Add error checks against get_min_max*() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260411-uac-sticky-mixer-v1-1-29d62717befd@rong.moe> References: <20260411-uac-sticky-mixer-v1-0-29d62717befd@rong.moe> In-Reply-To: <20260411-uac-sticky-mixer-v1-0-29d62717befd@rong.moe> To: Jaroslav Kysela , Takashi Iwai Cc: Icenowy Zheng , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang , Takashi Iwai X-Mailer: b4 0.16-dev-7777e X-ZohoMailClient: External All callers of get_min_max*() ignore the latter's return code completely. This means to ignore temporary errors at the probe time. However, it is not optimal and leads to some maintenance burdens. Return -EAGAIN for temporary errors, and check against it in the callers of get_min_max*(). If any other error occurs, bail out of the caller early. Suggested-by: Takashi Iwai Link: https://lore.kernel.org/r/87ldewi4j8.wl-tiwai@suse.de Signed-off-by: Rong Zhang --- sound/usb/mixer.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index a25e8145af67..e5993364c825 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1264,7 +1264,7 @@ static int get_min_max_with_quirks(struct usb_mixer_e= lem_info *cval, "%d:%d: cannot get min/max values for control %d (id %d)\n", cval->head.id, mixer_ctrl_intf(cval->head.mixer), cval->control, cval->head.id); - return -EINVAL; + return -EAGAIN; } if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, @@ -1388,6 +1388,7 @@ static int mixer_ctl_feature_info(struct snd_kcontrol= *kcontrol, struct snd_ctl_elem_info *uinfo) { struct usb_mixer_elem_info *cval =3D snd_kcontrol_chip(kcontrol); + int ret; =20 if (cval->val_type =3D=3D USB_MIXER_BOOLEAN || cval->val_type =3D=3D USB_MIXER_INV_BOOLEAN) @@ -1398,8 +1399,9 @@ static int mixer_ctl_feature_info(struct snd_kcontrol= *kcontrol, if (cval->val_type !=3D USB_MIXER_BOOLEAN && cval->val_type !=3D USB_MIXER_INV_BOOLEAN) { if (!cval->initialized) { - get_min_max_with_quirks(cval, 0, kcontrol); - if (cval->initialized && cval->dBmin >=3D cval->dBmax) { + ret =3D get_min_max_with_quirks(cval, 0, kcontrol); + if ((ret >=3D 0 || ret =3D=3D -EAGAIN) && + cval->initialized && cval->dBmin >=3D cval->dBmax) { kcontrol->vd[0].access &=3D=20 ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK); @@ -1743,6 +1745,7 @@ static void __build_feature_ctl(struct usb_mixer_inte= rface *mixer, struct snd_kcontrol *kctl; struct usb_mixer_elem_info *cval; const struct usbmix_name_map *map; + int ret; =20 if (control =3D=3D UAC_FU_GRAPHIC_EQUALIZER) { /* FIXME: not supported yet */ @@ -1856,10 +1859,10 @@ static void __build_feature_ctl(struct usb_mixer_in= terface *mixer, } =20 /* get min/max values */ - get_min_max_with_quirks(cval, 0, kctl); + ret =3D get_min_max_with_quirks(cval, 0, kctl); =20 /* skip a bogus volume range */ - if (cval->max <=3D cval->min) { + if ((ret < 0 && ret !=3D -EAGAIN) || cval->max <=3D cval->min) { usb_audio_dbg(mixer->chip, "[%d] FU [%s] skipped due to invalid volume\n", cval->head.id, kctl->id.name); @@ -2233,6 +2236,7 @@ static void build_mixer_unit_ctl(struct mixer_build *= state, unsigned int i, len; struct snd_kcontrol *kctl; const struct usbmix_name_map *map; + int ret; =20 map =3D find_map(state->map, unitid, 0); if (check_ignored_ctl(map)) @@ -2255,7 +2259,11 @@ static void build_mixer_unit_ctl(struct mixer_build = *state, } =20 /* get min/max values */ - get_min_max(cval, 0); + ret =3D get_min_max(cval, 0); + if (ret < 0 && ret !=3D -EAGAIN) { + usb_mixer_elem_info_free(cval); + return; + } =20 kctl =3D snd_ctl_new1(&usb_feature_unit_ctl, cval); if (!kctl) { @@ -2627,7 +2635,7 @@ static int build_audio_procunit(struct mixer_build *s= tate, int unitid, break; } =20 - get_min_max(cval, valinfo->min_value); + err =3D get_min_max(cval, valinfo->min_value); break; } case USB_XU_CLOCK_RATE: @@ -2639,11 +2647,16 @@ static int build_audio_procunit(struct mixer_build = *state, int unitid, cval->max =3D 5; cval->res =3D 1; cval->initialized =3D 1; + err =3D 0; break; default: - get_min_max(cval, valinfo->min_value); + err =3D get_min_max(cval, valinfo->min_value); break; } + if (err < 0 && err !=3D -EAGAIN) { + usb_mixer_elem_info_free(cval); + return err; + } =20 err =3D get_cur_ctl_value(cval, cval->control << 8, &val); if (err < 0) { --=20 2.53.0 From nobody Mon Jun 15 14:00:02 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FCBA3E3D9B; Fri, 10 Apr 2026 17:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843372; cv=pass; b=c3CuLc6WUJgXCld8qjobPehJnWp+MHMSUj5sASAbYqcfpEfKvYAIV2GkxQnZDkTt/eGjR6XzkD+Ny6Z3bfPDkC0FWL7/Pdb7JVLWfq/vfjSgzucqyGTkp5Gb99OWCpMzAC+qu7UQU7hWkzCt8/b2pGDtOxTS4v7sydZYQEpDO7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843372; c=relaxed/simple; bh=mETUt9k6JDPxxneKHhEm35pjoJWyMubho1yhlw9vQPw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SVciZ7KOrz8W+LnPtPzdkbxKd0nJ1gZTOuei7bf4ygJ4h7vCrJVJaAbdw3hV6KabnC3JWcVxTo/do4bgitPDmalyp6NMc4pIO42MRSJYT9qwb9arN0QgxeKqze9a3zng6/rHAxsCPxxSsaY/y/odUhipuh21VcHM9G4dcrXxHjs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=BLUQV3Ld; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="BLUQV3Ld" ARC-Seal: i=1; a=rsa-sha256; t=1775843365; cv=none; d=zohomail.com; s=zohoarc; b=iSssBFesKdar1NZm8MOGY3LHN5yLscCsfY12G6IosmdwJ7To/nxiFdcNkEQ7G5ZFZuoE1KUGYfo/9PW11qRq0Q31O5Vu1mVA7tF2jmJbF7SAg6oi/dqkvEiR9ExorV5ulgnSrcwcjwilGmCui1rpDWLAGy58VfH/+N8zVl8jZyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775843365; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=CBLpvIFklAKcz1OZtU2w+GwIgrjo7+BQ/Bq7bLzCADI=; b=IrXb1cmJNvDVadF2cXydZORaLGGbgkps7ZAKaHOLmZA3+7TXIAb1PzPNeWBan4A/BTHFxeVNf1bH/NVeBlTFqiwG4Jws+CtcgfRrjSPm5m4iumduDE3wytxkSxZgvXLZwm2kjND3nnWnORE3gC2cu8ciPB3xYFF/+tLhusKJEow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1775843365; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=CBLpvIFklAKcz1OZtU2w+GwIgrjo7+BQ/Bq7bLzCADI=; b=BLUQV3LdeT6Wp5ILVq36Poz7ID+VP1U/7zPs76hdVWg0Q/2Jx1JAJPbgPX4h4ep3 35gOqLaSkp+1361obF6Xl9O3WdGyePgWeQY+JcgCUQZWqWfLUepgIED84tGMOEo+pA9 kVnwUSVU6JPcsjqQuK3DOdIlovtG2vp+T+54kGj8P6vonBcLAq2mPypiU+xhsRV+rEr tA5r7jdy+0vxwi3cHlSah3iynYERYChaK49CpQtJAwWwixcSUyWtwW9+6eeRCQ5beex s/tU/hpqb1g3jEOLfeq0heY5m9eO8fmDljxDh+A26N0A/z64q2K0uH01fA38cRLbjax rTePQdmCRg== Received: by mx.zohomail.com with SMTPS id 1775843364741333.1102189571038; Fri, 10 Apr 2026 10:49:24 -0700 (PDT) From: Rong Zhang Date: Sat, 11 Apr 2026 01:49:03 +0800 Subject: [PATCH 2/3] ALSA: usb-audio: Move volume control resolution check into a function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260411-uac-sticky-mixer-v1-2-29d62717befd@rong.moe> References: <20260411-uac-sticky-mixer-v1-0-29d62717befd@rong.moe> In-Reply-To: <20260411-uac-sticky-mixer-v1-0-29d62717befd@rong.moe> To: Jaroslav Kysela , Takashi Iwai Cc: Icenowy Zheng , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang , Takashi Iwai X-Mailer: b4 0.16-dev-7777e X-ZohoMailClient: External get_min_max_with_quirks() is too lengthy and hard to read. Move the volume control resolution check code into a function as it's relatively self-contained. Suggested-by: Takashi Iwai Link: https://lore.kernel.org/r/87o6jsk3vs.wl-tiwai@suse.de Signed-off-by: Rong Zhang --- sound/usb/mixer.c | 65 +++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index e5993364c825..e77c2d78a782 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1232,6 +1232,38 @@ static void init_cur_mix_raw(struct usb_mixer_elem_i= nfo *cval, int ch, int idx) snd_usb_set_cur_mix_value(cval, ch, idx, cval->min); } =20 +/* + * Additional checks for the proper resolution + * + * Some devices report smaller resolutions than actually reacting. + * They don't return errors but simply clip to the lower aligned value. + */ +static void check_volume_control_res(struct usb_mixer_elem_info *cval, + int channel, int saved) +{ + int last_valid_res =3D cval->res; + int test, check; + + for (;;) { + test =3D saved; + if (test < cval->max) + test +=3D cval->res; + else + test -=3D cval->res; + + if (test < cval->min || test > cval->max || + snd_usb_set_cur_mix_value(cval, channel, 0, test) || + get_cur_mix_raw(cval, channel, &check)) { + cval->res =3D last_valid_res; + break; + } + if (test =3D=3D check) + break; + + cval->res *=3D 2; + } +} + /* * retrieve the minimum and maximum values for the specified control */ @@ -1287,37 +1319,18 @@ static int get_min_max_with_quirks(struct usb_mixer= _elem_info *cval, if (cval->res =3D=3D 0) cval->res =3D 1; =20 - /* Additional checks for the proper resolution - * - * Some devices report smaller resolutions than actually - * reacting. They don't return errors but simply clip - * to the lower aligned value. - */ if (cval->min + cval->res < cval->max) { - int last_valid_res =3D cval->res; - int saved, test, check; + int saved; + if (get_cur_mix_raw(cval, minchn, &saved) < 0) - goto no_res_check; - for (;;) { - test =3D saved; - if (test < cval->max) - test +=3D cval->res; - else - test -=3D cval->res; - if (test < cval->min || test > cval->max || - snd_usb_set_cur_mix_value(cval, minchn, 0, test) || - get_cur_mix_raw(cval, minchn, &check)) { - cval->res =3D last_valid_res; - break; - } - if (test =3D=3D check) - break; - cval->res *=3D 2; - } + goto no_checks; + + check_volume_control_res(cval, minchn, saved); + snd_usb_set_cur_mix_value(cval, minchn, 0, saved); } =20 -no_res_check: +no_checks: cval->initialized =3D 1; } =20 --=20 2.53.0 From nobody Mon Jun 15 14:00:02 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2A0D3E3DAB; Fri, 10 Apr 2026 17:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843373; cv=pass; b=U+vZ0SLsZRKlJqPvTIYHIgz1WQMbiCypm6RDzZj8GqDmO5cCW0s15ijWbTlbEJ7MNl+y30A1RiZESCWCd/0qTOxU9gl2k3sBiGSKfCt+3qYOotLIRF8olGWGmHlwUmLSHYxfC8/9YhXWb0UTsvKuNO9eX9zUvn/KGx2YbzG+UaE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775843373; c=relaxed/simple; bh=Md3rkaq4+nr/5QW5uyDPDn7eKL5WVj8e6Y/eolmq3gg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UKCQVMOprnYbQBv15dqZaE8B0W3I/NmmfzDE9Xi970D/WbM4qnVnkMwXK6EY9JUacGAtTPzxyREIDOSyJTEeymhe2d9PUlpjC4/Lfl1eNWirscqm6yq5xye7NCKzfl7Pyy+p+HgTKcchB7gfQmbdzjtDA5mNf6ywUrHCBc9C/5U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=ahVGZDZh; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="ahVGZDZh" ARC-Seal: i=1; a=rsa-sha256; t=1775843369; cv=none; d=zohomail.com; s=zohoarc; b=amnSQTAQ/J/uV8G5J5WzlVqs5Yokw98u0HR+xGiBSLewiRcUjEmm/EPjQHbIxgAFGiYklO/7W58GyTHVgt9z37g0wAwnfvZjKf55S8EeQVcj0zm2h7mP3HteDbvg07/BAV7z+/2I1EVwayX8+gmh8HzKcvvUb/h5ELreRdJRzRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775843369; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=QZ5K7I8Iu+fbtU8fbuh0FjkoXoLXYGZc3GXmfvioo2E=; b=FoFlnvQJD6gbkrsxIWcOVOa+oshYHkk1fFsafdWUvjjDL0epBMSKkVorZKKshx/xTuvlV4h9LmO6wZtXW3TSx2pduvXR/VXoBEUvVLdNpjbKhQ7bVZSK6T6VKlrifV8qZeD6W83LnSTNcYnLN0LuEcDTAG3oAUh/t/tw8YRD/I8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1775843369; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=QZ5K7I8Iu+fbtU8fbuh0FjkoXoLXYGZc3GXmfvioo2E=; b=ahVGZDZhSKaQ8JsOD40yxg/i78L+u/+oxs1WJMGiY0MWjsJztzdT8IxDed0lqq2X 33B1y9K2gCT8M6wqJ8wA4Xknd5zDHGyync4+PYBeOjw2Vdu4OxeoawH+tSwsajWFp2J jyPHYL2LvdqF9I8SAM172SBeqahr5MPh23lfsnGyQloPXmKUzYyjpMVP+gYEsBc2ADo 37BjLibHrgjBs8el4N9LImtoi7jH9vxHMICXNHFGFCe3k1x1o76epOFpSiiycsjazPV zAGPfgkLDr9hv33Ey4E3FTCqcDP3A8fht/aN6F3gsYwSt2dnSuihvuYACMwYI9u82mj JxGn8SvQVA== Received: by mx.zohomail.com with SMTPS id 1775843366861958.5126226545515; Fri, 10 Apr 2026 10:49:26 -0700 (PDT) From: Rong Zhang Date: Sat, 11 Apr 2026 01:49:04 +0800 Subject: [PATCH 3/3] ALSA: usb-audio: Do not expose sticky mixers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260411-uac-sticky-mixer-v1-3-29d62717befd@rong.moe> References: <20260411-uac-sticky-mixer-v1-0-29d62717befd@rong.moe> In-Reply-To: <20260411-uac-sticky-mixer-v1-0-29d62717befd@rong.moe> To: Jaroslav Kysela , Takashi Iwai Cc: Icenowy Zheng , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.16-dev-7777e X-ZohoMailClient: External Some devices' mixers are sticky, which accept SET_CUR but do absolutely nothing. Registering these mixers confuses userspace and results in ineffective volume control. Check if a mixer is sticky by setting the volume to the maximum or minimum value and checking for effectiveness afterward. Prevent the mixer from being registered if it turns out to be sticky. Quirky device sample: usb 7-1: New USB device found, idVendor=3D0e0b, idProduct=3Dfa01, bcdDevi= ce=3D 1.00 usb 7-1: New USB device strings: Mfr=3D1, Product=3D2, SerialNumber=3D3 usb 7-1: Product: Feaulle Rainbow usb 7-1: Manufacturer: Generic usb 7-1: SerialNumber: 20210726905926 (Mic Capture Volume) Signed-off-by: Rong Zhang --- sound/usb/mixer.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index e77c2d78a782..d4ef45bf53d7 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1232,6 +1232,41 @@ static void init_cur_mix_raw(struct usb_mixer_elem_i= nfo *cval, int ch, int idx) snd_usb_set_cur_mix_value(cval, ch, idx, cval->min); } =20 +/* + * Additional checks for sticky mixers + * + * Some devices' volume control mixers are sticky, which accept SET_CUR but + * do absolutely nothing. + * + * Prevent sticky mixers from being registered, otherwise they confuses + * userspace and results in ineffective volume control. + */ +static int check_sticky_volume_control(struct usb_mixer_elem_info *cval, + int channel, int saved) +{ + int sticky_test_values[] =3D { cval->min, cval->max }; + int test, check, i; + + for (i =3D 0; i < ARRAY_SIZE(sticky_test_values); i++) { + test =3D sticky_test_values[i]; + if (test =3D=3D saved) + continue; + + /* Assume non-sticky on failure. */ + if (snd_usb_set_cur_mix_value(cval, channel, 0, test) || + get_cur_mix_raw(cval, channel, &check) || + check !=3D saved) /* SET_CUR effective, non-sticky. */ + return 0; + } + + usb_audio_err(cval->head.mixer->chip, + "%d:%d: sticky mixer values (%d/%d/%d =3D> %d), disabling\n", + cval->head.id, mixer_ctrl_intf(cval->head.mixer), + cval->min, cval->max, cval->res, saved); + + return -ENODEV; +} + /* * Additional checks for the proper resolution * @@ -1270,7 +1305,7 @@ static void check_volume_control_res(struct usb_mixer= _elem_info *cval, static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval, int default_min, struct snd_kcontrol *kctl) { - int i, idx; + int i, idx, ret; =20 /* for failsafe */ cval->min =3D default_min; @@ -1319,13 +1354,20 @@ static int get_min_max_with_quirks(struct usb_mixer= _elem_info *cval, if (cval->res =3D=3D 0) cval->res =3D 1; =20 - if (cval->min + cval->res < cval->max) { + if (cval->min < cval->max) { int saved; =20 if (get_cur_mix_raw(cval, minchn, &saved) < 0) goto no_checks; =20 - check_volume_control_res(cval, minchn, saved); + ret =3D check_sticky_volume_control(cval, minchn, saved); + if (ret < 0) { + snd_usb_set_cur_mix_value(cval, minchn, 0, saved); + return ret; + } + + if (cval->min + cval->res < cval->max) + check_volume_control_res(cval, minchn, saved); =20 snd_usb_set_cur_mix_value(cval, minchn, 0, saved); } --=20 2.53.0