From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796499219; b=trS9nG+W58LbPn7yUPfiR/WdLjvp6kGMEy/X4UJ3KaUSOlhbDpxdxTxRRZS6odzvsVt1 Ljzef/AGoAlqCyOGjrMKsBT2itX+OzVCEW6jbK4NFFq5EnLyD3csi3wGe6MPcdLS1JImr E6qYD5YztTKPCp2ZNOIZ6w0j89aLppXm5KAT6yc7xReRT/ddOpYaZHn6AkKikIQGZex1r u/XxOmKG2jrQSyr+nw7XQY2KFVObO+zC6QtaH+NvezO5FXhJegt0XIAcZjINmUzlpJV8f pFMXAoDDBZwNiGQ5A4/iLVDfvCclRQhhhCOhAXiyVDQAJ5RxKIMF6zgd+/prKfTDllg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796499219; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=Fl6vnz132CnHKO6Hu7t+JAGrUNqND0A8xTWmWmX2q/1RJykBidp99+vk5oDO/O1IfrmB P1iuEb7Dqtc4vRt0JMZydpeoo8g8NOTEU1c6Nc0H0CbVTmosveytlzg5YPRHE62GUdUmS PW9jvKWnxPR2o34S/YbYWW8Y1XyfVNFxp6q8CmFimnqmZ/J1Txl4dfwR5aawaCemI53BM pYsgopL0EuqAFpkuo7zyKO2AEz4y7fJcRnAvGIOSn/L5Yfryk0DWzmKdNoI/VdW3ZiqgA 1j/uJXzP7Alt6UzQVAGh/iVvx73EwR4r6pzhfT8YB6RO/g9PTM5bBMHQByle9egEDhg== 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.172 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 26064606A337 for ; Sat, 5 Dec 2026 19:33:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 26064606A337 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-f172.google.com with SMTP id 38308e7fff4ca-3aff86b9d91so18250671fa.2 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=Rh4ImhYzXaBzZpeWORjsnpaCYjJNEaZsrcgf40uREY0MMGoYP3NbjF2e7JCi7tu3ti uWPVwQmEMRDf19peTD32Nls7kozIWpGvLlGuh59TM/zrQcatP0h98viHPLnyg7mR8LKu sMuH67rEqLOsBJwJSL+EO0gAxBEbaFE9tOp4Owvi1VfuO+vS9lP7baBE7s3EtUGOSzm5 gZHlZyuDxpFDaaX3d2Mw31SVqMdCH//c6aIyttn0DiNyYnnLy7C19jQi+jL3AaqeK5Bu di4Wss00dxgjT3OMp8P1i7bxZFZTNDlm8haLvEM86UesadBd9VGNnVkOrBBSgPwJ+tgP 393Q== X-Forwarded-Encrypted: i=1; AL+hErGxHPItK1ILHT8mDhlcaCIL1bKQfiB1sJlPodNx42W/jjCuen4jOU9JYvcDEYO7IOV1SjyLXoMP+xyqF3k=@vger.kernel.org X-Gm-Message-State: AB4q+uEb7pNGVhySApsxlldAHI82qzawS+1IO0PDuh7BUEAwySUDSSgp i2v4R02J+KGvDPOUufvFO88ZBjtgvTD0dKRMS5LwjHkR/PnH8OIbnrVe X-Gm-Gg: AZFdTZcqYEUI6uV2hpQcG72rQKrDo51vjfpJK6BNy3ZdIVALhyIEtRqcjf949NlEmj6 8N/3Ukx9G76g6RPEPRtxGH+Sq54Ta/KJoyfUA5e83gQEa7e3rkQz+XKN0+jmZyYoFF5k+3lJfrP 1w6CxUCBxoZu0k8/hyiJ71dpD82UhA9luZcy87N6QWTpeRaj21aqxvQ1Wyy8RK7PEbc/Mn/jP58 17FeRSSgGRVF01+bFcTdXoDGhVVCFUh5xoYhxp/WOO5qu9wKqnFMQHtSRPD8SLIUJn8IRWTr5kM Pg3b87/ugurOqg8REwmbldSQYIdNjRaP+StfJIpF95hJerQNQUxriWplG7l3Veo7ZI/MpD68Smq WuBEiB8bNpFKFMgq5H92VWgW4WsvyJ075CeCFwWUncImhost2OeFH6um4JSXKO55V+P+ez1DyNA cG+oh/5KAm5YE8XnJsx4amDLqxcSDnBpeXuSMpFnyNhHYQFdId5Dab5ggAyDNB3vOkQ+/Iph+Ue lhqFzwSygbjaKUoY514j1jACzOU4mmD+gbH8M0FDw99JsXtIA4evpmh00lZ0sPESbeFGvxR43No gAa9Q5vqkJzdz+5Ctd6Z3yrxeA/li5sCPqoGmm7KgoOZ+9X+MJEkJY/YAO8h0NiQZg== 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-kernel@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