aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Walpen <dev@submerge.ch>2024-02-26 23:27:47 +0000
committerChristos Margiolis <christos@FreeBSD.org>2024-02-26 23:27:47 +0000
commita9341f0f0ae01b4d249dbf3bacfa420152c46aef (patch)
tree3559e40e3ebc43ce817facd4915146ddbf5f5950
parentbc4c7e78f84577c33bec6c1a4ab60e99560a4bf7 (diff)
downloadsrc-a9341f0f0ae01b4d249dbf3bacfa420152c46aef.tar.gz
src-a9341f0f0ae01b4d249dbf3bacfa420152c46aef.zip
snd_uaudio(4): Fix sample rate selection after 42fdcd9fd917.
The sample rate selection of snd_uaudio(4) at runtime was implicitly relying on a specific order in the device config list. In case a default was set through the hw.usb.uaudio.default_rate sysctl tunable, commit 42fdcd9fd917 removed a duplicate sample rate entry from that list, which inadvertently broke sample rate selection at runtime. Implement sample rate selection in a way that works for any order in the device config list. Reported by: Lexi Winter <lexi@le-fay.org> MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D44051
-rw-r--r--sys/dev/sound/usb/uaudio.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c
index 26d95bf3ee9f..5d7396c527e0 100644
--- a/sys/dev/sound/usb/uaudio.c
+++ b/sys/dev/sound/usb/uaudio.c
@@ -2768,20 +2768,19 @@ int
uaudio_chan_set_param_speed(struct uaudio_chan *ch, uint32_t speed)
{
struct uaudio_softc *sc;
- uint8_t x;
+ uint8_t x, y;
sc = ch->priv_sc;
- for (x = 0; x < ch->num_alt; x++) {
- if (ch->usb_alt[x].sample_rate < speed) {
- /* sample rate is too low */
- break;
- }
+ for (x = 0, y = 1; y < ch->num_alt; y++) {
+ /* prefer sample rate closer to and greater than requested */
+ if ((ch->usb_alt[x].sample_rate < speed &&
+ ch->usb_alt[x].sample_rate < ch->usb_alt[y].sample_rate) ||
+ (speed <= ch->usb_alt[y].sample_rate &&
+ ch->usb_alt[y].sample_rate < ch->usb_alt[x].sample_rate))
+ x = y;
}
- if (x != 0)
- x--;
-
usb_proc_explore_lock(sc->sc_udev);
ch->set_alt = x;
usb_proc_explore_unlock(sc->sc_udev);