From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796499218; b=aK4zCgJMGZ40wHPwbwQJWheq6vpa1jVz+7kl6yRz+FAkzTJrs7cq2Ds00q0BLIXppZ9j c4HIPdSUT+GBUowPFFD8leM26jT87iAGMcLOvwS/OWHb6vQcf7dAzyJ47gWEtusFovmbf uWn9k9XdIVqCfRbzjpy8JE9OqFgdtt0sH+mqN0jfKRMEPK8cPsFDzoPWebVqxZvtaed1F Ktn+NIu88rr/n4Vz7IioR8gN9SDZu4EraVDlklOWcdeA60W4L8kV6ZH7xl1lNCPYfm2Bm uVzQBwkek2lf15kjAhfmTbl51cEraOrq8b0o/+sLcKc+wzNH6L2rWbBfYqXzMG+YeKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796499218; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=lxPo49P1ArrViMR+OgPc9iF6pFe/T1jHnuRhCCtfUb8=; b=souPHtyos0PellfAHGFZt7+jQDaP2uEC9lbgn1nB/WEbW2YX2VoDQ4u6Syxv2enZJvTH so89tx5B8Jih02UEC4COa7QX3aMz7hjL5hvG6vGT1UmOFLzJEhjfzHS5hHDWWqy0aIixx 28GMLnK412hIq4BRR9DpEi9HR9CwJIQw2GIHzTIQzAyGMvlgR3OhWYzRygta5DempCXph oICLkG2mu6rQuSs2Ma7P9+T27BUUumSg6U5lgofRYkCFBSpspUz6/0mHYzsEM58zoVVRy Gyz3GO1m5+LobPoFAozFBe3nKW9+UvDGizGt+CNLtMmBqKn8CqPQB2hhecvHMe7UNjQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=U3CPrlLr; arc=none smtp.remote-ip=209.85.208.180 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E00F606A334 for ; Sat, 5 Dec 2026 19:33:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1E00F606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=U3CPrlLr Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-3b0082525edso12095731fa.1 for ; Sat, 05 Dec 2026 11:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796499216; x=1797104016; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lxPo49P1ArrViMR+OgPc9iF6pFe/T1jHnuRhCCtfUb8=; b=U3CPrlLr2fJJmVSSngRWfttv8nZlXxumsouY22tmqAvo2O5hm0xgSS73v7lUc3Rq15 1nZVlynD/R/S8vhxcZf1TX+qJzN1GrvcExobGWxwMVG9dApeMf5Wbr7EAIHl5jHUOu41 HPjd7LWvGq0AT7QWfKH/KXhRCeXyrihoKE50R699SPuuStsyxXy5g3/EQOhNsuz+hC40 J3mxde2EzdI/OTOXrfprsBjUtUlDZlbO++veoR1eCK1SOSgrMM4IEGm/f3DHvMoHs3Lx DW6RYhiNoUee35cnwyfXvlwr4S+1I0YrdSaMS95cfLuG6ltq/zX/dHrQLg7yutr1pZ1j VM1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796499216; x=1797104016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lxPo49P1ArrViMR+OgPc9iF6pFe/T1jHnuRhCCtfUb8=; b=Ed4Dw+Cl8ke5OnWwuqufIE5iGVKpjzs07NIe4SNf/oHji+rNB+WpwBYchbc+/+T9Jc 3M5EyzKQmwz7g0k7nv+69syPXFA+MV5VCIonNCOKRzKzhq9rYQzxPOcYAdQDox/hlFnN C3GJ1uN6nDhHcouVV+pq8KQhM7kLoOukcox0sbtsBFXNSeX/A/fYZAA/QDxTzSnzlWIw h+7rNvcYcpdpTObXaezSiqF2UkYAxhs94P5mOtaBu5zrE8bu0qV69iJ+7JSlII8sYb1s dYxBnptTFJ6dZl6re7MzyqD7WxDVSAy34KXtP0kIraInlkNIX7Z89fGkgQy7IjNTLaW7 mIOA== X-Gm-Message-State: AB4q+uHgSZbbDDlsIxo60FhyAudbMF+GdMOKLWIjMdpB9Yzcm50RpnWe RsSU8bWoJNNsKq7bQo+6W2Q4Nrx0YGZ+WmjGK2gme5w5pPTr8/YmyEcF X-Gm-Gg: AZFdTZfoXG1yytycQp8SqU/BPqSCTTEQ8h2pj1OJEqt2ztYCJISeoCOOc+A2VBg5Iqq rkzPNivfyW7dXcXtYa0MdJHmdhhp8T124LYoBkznrn9ooaZE/W/Z4ZFxxpyTow4vraM2Zih0Be6 BK4JNOgx5WjiFnsmpQxNDA93FnpYsABCm9/mt0PApVufk2zxUJpN1PiDJRsO2jXcG6RACCkyL+b icPhz4kV7OOIdUvelJfhehfPR87Aa3tGF5CBRuBWi0V5quhBvJaViY6KPZ4JMNp8V+hU9S/wZp7 mLNm6TXuGBEEhQN/bfjkivWlnnLwos4yC3FhB60rGmdkw66ctJFkdFxmn3zwm6KWSKBV5HQxbNM /PCypepSowQAwXDqvuaEPXgV+5NrkEnrsJdtpScHxJs/W/R5btxVHfkpw9hkB6SiGe8hHo1/Wtc Ule+JAF56A61T+t+dSdUIjdu+icBru4jKBuGdLLLefzNqikfEKxyomAOl3ars6JYBd6ZtyIbgna nsKu1p1erBDij0+dcMeabUXyO3JUYSoEIJQeiEDPUFt1ez9Jk0mqg8Q8T1NMUYcy4Si0qLxpLRQ LH3Jn+ovnAPry1ANMuVX0QfEvoYjh+RO96TCZ9Ve3RTYoG+N3NXWiBKH7epX9YIjsA== X-Received: by 2002:a05:651c:c006:20b0:3b0:bc6:da4 with SMTP id 38308e7fff4ca-3b00bc610dcmr7282141fa.27.1796499216268; Sat, 05 Dec 2026 11:33:36 -0800 (PST) Received: from v-nix (static.209.21.27.37.clients.your-server.de. [37.27.21.209]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3b0035cd9cfsm19865031fa.0.2026.12.05.11.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 11:33:35 -0800 (PST) From: Lee Volkov To: Takashi Iwai , Jaroslav Kysela Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Lee Volkov , stable@vger.kernel.org Subject: [PATCH v2 2/2] ALSA: usb-audio: Reuse active sync endpoint format for implicit feedback Date: Sat, 5 Dec 2026 22:29:28 +0300 Message-ID: <20261205192928.27775-3-voilthuman@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205192928.27775-1-voilthuman@gmail.com> References: <20261205192928.27775-1-voilthuman@gmail.com> X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On devices where implicit feedback shares a capture endpoint with multiple altsettings (such as Solid State Logic SSL 12, where 16/12ch capture altsets support up to 96 kHz and 10ch Altset 3 supports up to 192 kHz), opening capture on a non-first altsetting (e.g. Altset 3 at 48 or 96 kHz) and then starting playback triggers a failure: snd_usb_find_implicit_fb_sync_format() scans subs->fmt_list from the first entry and picks Altset 1 because it also matches the rate and channel-agnostic check, ignoring that the shared sync endpoint is already open in Altset 3. snd_usb_endpoint_open() then rejects the mismatch in endpoint_compatible() and fails playback with -EINVAL ("Incompatible EP setup for 0x81"). Pass the caller's current subs->sync_endpoint (ref_ep) so we look up the live sync endpoint with snd_usb_get_endpoint() under chip->mutex and only reuse ep->cur_audiofmt when it is in use by another stream (ep != ref_ep || ep->opened > 1). This prevents a repeated hw_params() call without hw_free() from pinning the sync endpoint to the caller's own about-to-be-closed format. Fixes: 5d15f1eb4560 ("ALSA: usb-audio: Choose audioformat of a counter-part substream") Cc: stable@vger.kernel.org Signed-off-by: Lee Volkov --- Changes in v2: - Drop superfluous #include (Takashi Iwai). - Pass subs->sync_endpoint as ref_ep from snd_usb_hw_params() and check (ep != ref_ep || ep->opened > 1) before reusing ep->cur_audiofmt so a repeated hw_params() call without hw_free() does not reuse the caller's own about-to-be-closed sync format (Sashiko AI review). sound/usb/implicit.c | 25 ++++++++++++++++++++++++- sound/usb/implicit.h | 6 +++++- sound/usb/pcm.c | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/sound/usb/implicit.c b/sound/usb/implicit.c index bd4d569a8..755df2b1d 100644 --- a/sound/usb/implicit.c +++ b/sound/usb/implicit.c @@ -16,6 +16,7 @@ #include "card.h" #include "helper.h" #include "pcm.h" +#include "endpoint.h" #include "implicit.h" enum { @@ -459,10 +460,12 @@ snd_usb_find_implicit_fb_sync_format(struct snd_usb_audio *chip, const struct audioformat *target, const struct snd_pcm_hw_params *params, int stream, + const struct snd_usb_endpoint *ref_ep, bool *fixed_rate) { struct snd_usb_substream *subs; - const struct audioformat *fp, *sync_fmt = NULL; + struct snd_usb_endpoint *ep; + const struct audioformat *fp, *sync_fmt = NULL, *active_fmt = NULL; int score, high_score; /* Use the original audioformat as fallback for the shared altset */ @@ -475,6 +478,26 @@ snd_usb_find_implicit_fb_sync_format(struct snd_usb_audio *chip, if (!subs) goto end; + /* + * If the shared sync endpoint is already open by another stream in a + * compatible format, reuse that active audioformat instead of picking + * another altsetting and failing endpoint_compatible() later. + */ + scoped_guard(mutex, &chip->mutex) { + ep = snd_usb_get_endpoint(chip, target->sync_ep); + if (ep && ep->opened && ep->cur_audiofmt && + (ep != ref_ep || ep->opened > 1) && + match_endpoint_audioformats(subs, ep->cur_audiofmt, + params_rate(params), + params_channels(params), + params_format(params))) + active_fmt = ep->cur_audiofmt; + } + if (active_fmt) { + sync_fmt = active_fmt; + goto end; + } + high_score = 0; list_for_each_entry(fp, &subs->fmt_list, list) { score = match_endpoint_audioformats(subs, fp, diff --git a/sound/usb/implicit.h b/sound/usb/implicit.h index 7f1577b6c..554f70a77 100644 --- a/sound/usb/implicit.h +++ b/sound/usb/implicit.h @@ -5,10 +5,14 @@ int snd_usb_parse_implicit_fb_quirk(struct snd_usb_audio *chip, struct audioformat *fmt, struct usb_host_interface *alts); +struct snd_usb_endpoint; + const struct audioformat * snd_usb_find_implicit_fb_sync_format(struct snd_usb_audio *chip, const struct audioformat *target, const struct snd_pcm_hw_params *params, - int stream, bool *fixed_rate); + int stream, + const struct snd_usb_endpoint *ref_ep, + bool *fixed_rate); #endif /* __USBAUDIO_IMPLICIT_H */ diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 57a26492d..5f19cbf25 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -507,6 +507,7 @@ int snd_usb_hw_params(struct snd_usb_substream *subs, sync_fmt = snd_usb_find_implicit_fb_sync_format(chip, fmt, hw_params, !subs->direction, + subs->sync_endpoint, &sync_fixed_rate); if (!sync_fmt) { usb_audio_dbg(chip, -- 2.55.0