From nobody Mon Feb 26 23:29:29 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TkGzY3gr2z5Bv2H; Mon, 26 Feb 2024 23:29:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TkGzY2qJgz4YBJ; Mon, 26 Feb 2024 23:29:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708990169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n4m3elA+1cGepddmTPNjNAfgfvheY3BAqnYZqGQQink=; b=lzpCp2Ui7jABTvhX6BlWI/Lc1xeRRrNzA1HN9yq7kvaUWAgUW86y7pFXLEbYCoe6Xk3VQQ 84YvBD7Umet27dO4mTUO2G1vtlDKocoqwzvBBaiTaIdARLOV2ObnnsKiXbVNpbtcKwRaLR IS/HkM0ZHklwsP1LIpUaqK29noag4gNsYUjVRShocLZ5DfoCEVEAwjoJEA14M2sR2r7fGw QwiJQWFw2xlG6y/OtRttBdQhwaMh8FbamZ+rh+/UXquX5cpKFL4Ikwf0gV7/lUiW7CO15w pC/eVinUrTbTJZNq8UFKLjC/bvXKHofY5jDpGzN+KkrP/3e3KfcAUDvw/2CO1g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708990169; a=rsa-sha256; cv=none; b=tJo2T6niQmnHhsXbqHs1Wwq8KpGoq7qLpLoXd+H5lYuO4naX+VqPmt6JJOPdOccN8DmcCR lv2Jfge1ZOq/UbblPI1bU2D2L4uyfEPgljm60VjK5sp1fu47GOdq2zMJkHIkqN6tLTwwYH u9Hj+ithOfPMgPn6euuen6/SvMbwxfMkz+pUQhGBzpZ0d30AyBlVyEdZy6mttU5jiGMQ3V kTvkUTL8pPCZ8sVn/HiuUeIgP74+XPC5f9Hy33ESul4Cnf5krAOoPVdokqHZUSrqzSQidx BaCy+WTATwTNnSDu9BrCblyLv+siItswiKmD2xhGzc2Q8Kd4IHKJ9vHbE6dbmg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708990169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n4m3elA+1cGepddmTPNjNAfgfvheY3BAqnYZqGQQink=; b=LGQiFkW/ZisawYF8NMtCa46RMID6jBwBowqa8gUY74Pm8TDjjPYDZTOkf+TXaNipgBRBj2 hFEUKdDPkEXlbY4mpGts8rEiTKIC5mGgaC0tsVTjyJzdH3Ogt/n692I9BCBk+97Q3NwlII DEko8Kv87YoEh6T9QM1CDmumJguf5OM/oPkYRUu/GqvLkpdiT5H38IFmCoYdASs7bxbWK7 BXWZ1f43NgI5+PcPFZ2fP++7BNvHhecHXiAU4zYjkvs4bZfAsVmdYbNmndAoDn8PVgtces 1TH6dqwK1bK8TIl3DiT9C+mEEsz+O0VRmK0R/mHKJrbK/siIIZEeh4+bA2850w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TkGzY1v08zp7S; Mon, 26 Feb 2024 23:29:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41QNTTQ6030561; Mon, 26 Feb 2024 23:29:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41QNTTdM030558; Mon, 26 Feb 2024 23:29:29 GMT (envelope-from git) Date: Mon, 26 Feb 2024 23:29:29 GMT Message-Id: <202402262329.41QNTTdM030558@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: a9341f0f0ae0 - main - snd_uaudio(4): Fix sample rate selection after 42fdcd9fd917. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a9341f0f0ae01b4d249dbf3bacfa420152c46aef Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=a9341f0f0ae01b4d249dbf3bacfa420152c46aef commit a9341f0f0ae01b4d249dbf3bacfa420152c46aef Author: Florian Walpen AuthorDate: 2024-02-26 23:27:47 +0000 Commit: Christos Margiolis CommitDate: 2024-02-26 23:27:47 +0000 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 MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D44051 --- sys/dev/sound/usb/uaudio.c | 17 ++++++++--------- 1 file 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);