From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796162948; b=WIohw7shwG/r54v8iXW6MumIdYfA2rPIrIbO0z+JDgTb2bzdFVvFuU6Kf5HIA1i3IKru Wqnu6N+65F147J0jRz8n4PJUdIopmmywBS7JhxBx7SVnNqxnIoUuK8P64R3T7uzar9wTu UUNNdvNJcMcO92s/j8Ag/+RQdYTXLb/QSUgwMrwCkAz5ZLAnq5FczsaxWA5Y2HnqF2vLX q9yA/xy2LhOkq8mKmKlxXdaYilmEEeS0BGWdziRHQjUqktywpT8SWkRVtbfI+Oee9YW4E GlzxGEF4glZhwYfLZ7Mz9+zqQ7J2sbQwmOffi1K7u88GIf9uOCMbeQY5HRlsqQhlTgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796162948; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:Date: Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer:X-Authority-Analysis: X-Proofpoint-GUID:X-Proofpoint-ORIG-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=ef1a2uo7quvteKhQFq77xLvOQcA3Ple8pV/zycYwKXk=; b=PpNyUxgyfgkcbL0lmaYnPS4RtiDYDMq/LZqrxfiVwvEGrE+FLTvhknKeFWduefNdMrAN uo6r+qFoR29tLnFFv8zIIMgcJdS8wSc6dIYKtRcNwz0fl+a/NdjlgyrXMlugV5g5Rnot2 4lypqxk41xF8orOaWA8t3T/w1tlWp2dZF028mcsgCjh3DaSimvG2E9lkOtReEDh1nNOyU 8aGgebqkBe3fIaHN8W2OMgccgo5wiD0vsLBCkY1pRyBB0gxMo0iHL4ZvF7TEhU9FP/ISb +pOEOwAhD6BBx+HSqhR8+Npm+b82tS4kw9mhlDAFS8rDC+zEbxrBntvVnP4/4jGvLWw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=jVwpNEMC; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=hZRUDip0; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84781606A68D for ; Tue, 1 Dec 2026 22:09:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 84781606A68D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=jVwpNEMC; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=hZRUDip0 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1J0wX82001432 for ; Tue, 1 Dec 2026 22:09:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ef1a2uo7quvteKhQFq77xLvOQcA3Ple8pV/zycYwKXk=; b=jVwpNEMCJ7b8rGWe YVaeKi19rZcKb1o+jqaGbpR/ZD5oiVxjByqceZkopm4N5xUklO4LY0Ym9I68kNSb MK/mJIaB+PC6YTIuJkxLFRBT6HZWx2eT2V3C0A7zqIdiLNO78y8wXWaAcNdilElK ig5G5cq5BtNyufnYZ7lE9xfgXml06WyJtSGQ+6OdNJh7CeaWHEIJrwzjo5WRa3tD 3nhT4l9Bdl6Q2kiPvZurbrl8I43Xx0iXyqI47lgJYzizwYpM+HRMRLQT/n4vbnML hL/ZRAsR0asP6RKXHyQjxXlKim0v1rHQrF+4VafKgY/dML4E+SwA0E1w37rQre7n eMbtDA== Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ja3aj0tbe-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 22:09:06 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-386177b0516so5218000eec.1 for ; Tue, 01 Dec 2026 14:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796162946; x=1796767746; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ef1a2uo7quvteKhQFq77xLvOQcA3Ple8pV/zycYwKXk=; b=hZRUDip0ry8r+BqxCyjGEp6lc7d6V3RrcQ2wL3yj25UGeW5Lmrh28I/6jaY5KL2b3/ 6P+Wx3gzC9a6O/AautWFfrlmbhB6l7bu6Os3L+2GoemZDSGYrrPgeCCnfRgBAzSjaM9K 6HOTIdw0d7BzdkjTXMyBY3L0kGtQ0dCYg13PaTqWx8ZoQ0Zumz/aHL+CNpf2INYtV0xk 450Nlu9SEunjwNOyAdfQA5QiBz0ORJmu5sWLiWthRBSWqJho96FeJqkn3BHaJc2Oas8A PW7/H/YTSyff6nj459FRPZB0t8GIzKOwIqnFy6TwOFt90J3+zUYchjPn9tEATu0iudnK wVEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796162946; x=1796767746; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ef1a2uo7quvteKhQFq77xLvOQcA3Ple8pV/zycYwKXk=; b=UB0ZURXjK1XrOsji67xTPD4yEnqOJYA03InFPLN8KdG1Seh5uHqcvZpV2Lr3na8SfP tPiZpcKpeW9bk4m19mP52tUyfqTZur7HAqQYkD8zreDlOChZELWIO5wVyI8W/YwO96Zu nz0gk6SgiCdIz7Yme1OTKRo6OCFsn/BgTcesVsa2myOGoO+Q1YEEgFqcj6o8pDVgICVM owYBt+VgyQjrme+46x1vZlfCg4Rxktl55B6LhMkWedHNSyPr8a4rMItrPhhXgiXWpi9o 0Tp3DdKOTS5VSj0EMdpQRC1CUQgo10GjmMDcQJHGZExncQmJFZpQZcvx2G2WnF8gPj7G HMpg== X-Forwarded-Encrypted: i=1; AL+hErGfpsa38Z+nUXGkxyPcYBk9440+Rjf2hvSQvTd4Jvkt0T7iz9Vo1faoCzo1oflnDShJ+IzlrjpQgODGWFE=@vger.kernel.org X-Gm-Message-State: APuU4Z9jFL6irbIrikRc6R38/MxJW8DCsU2wRMDAxKWdmrRGuec0Vp3z wQ4nxxMGV2RUVgo2L3R4GHZqL1oUyt7NVORZUrvGgRbaHJu2aX8k0gmwxPYLedIThUoA0kN+y8c 5dph6kw/dnhTz/ZpMHnnVcoJQUyu8HooL+JrOWR/ndtOrwPgK66L6P6lI51saBeuReDw= X-Gm-Gg: AZFdTZdDao32IoR8xxUvz+2vX6VOYA4DJoQhuscw2IMam+CDXcpwyk5X+UTsOmJq8Og +aATFbqdWSZsnxN7ZD00toIHIq6YV9NOuYWJtpC1hd7t58xy5DX1wB6060LrdYlEhwZiDQ8iXu7 +PAcKNCPo/PwED5pE4rEuaeo0YKz8G2G+vOwbmSYkE82+lOSaKys1vJN6pfn9a8flYSmDoz3AMv AjgHpNZnrPme+jN4CPIQ/Awz9yowqaXHVRbqhMiILhvg0whP4WGEHkkXN0MGdiI4aae0ZXFDSoA 4qHEKzLGB/PmRqBuj0F/GoK7xNTAIC5fSEDSVdmMMmC2NGp1tmlJU/o4YDSVnDhujKosU5WV/xq DO88djELFu7rfXo0ytgD82WW1ceQKi8r4L+as0GwbBFUYXCzFemvl4K+WFnAMFLDcW++ggIht0L sUfGMF5464AL9c5HfpPdVTA6YD X-Received: by 2002:a05:7301:dd94:b0:36c:9afe:fcd8 with SMTP id 5a478bee46e88-3856f559cfemr35704271eec.30.1796162946041; Tue, 01 Dec 2026 14:09:06 -0800 (PST) X-Received: by 2002:a05:7301:dd94:b0:36c:9afe:fcd8 with SMTP id 5a478bee46e88-3856f559cfemr35704246eec.30.1796162945403; Tue, 01 Dec 2026 14:09:05 -0800 (PST) Received: from hu-wcheng-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386f6651e2asm38279881eec.27.2026.12.01.14.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 14:09:05 -0800 (PST) From: Wesley Cheng Date: Tue, 01 Dec 2026 14:09:02 -0800 Subject: [PATCH v7 3/4] ALSA: usb-audio: qcom: tag sideband endpoints before ring allocation 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-16k_offload_v1_b4-v7-3-ad9ddad2530d@oss.qualcomm.com> References: <20261201-16k_offload_v1_b4-v7-0-ad9ddad2530d@oss.qualcomm.com> In-Reply-To: <20261201-16k_offload_v1_b4-v7-0-ad9ddad2530d@oss.qualcomm.com> To: Mathias Nyman , Greg Kroah-Hartman , Jaroslav Kysela , Takashi Iwai , Michal Pecio Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Wesley Cheng X-Mailer: b4 0.13.0 X-Authority-Analysis: v=2.4 cv=Y7xtIReN c=1 sm=1 tr=0 ts=6b0f4582 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=qIinn66zJS-xtNAvlrIA:9 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-GUID: vqRdMuVJ3YMg08Fb8bjdlvAfhgN4YqbD X-Proofpoint-ORIG-GUID: vqRdMuVJ3YMg08Fb8bjdlvAfhgN4YqbD X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA4OCBTYWx0ZWRfXzQwxHDC+3iZv D7p7+Va1MViSXQJxK85wwgWWVi2AP+Zl7fo9/37agbp3ZQwx5uI2R39T+cRbOf6yNB4yNfg09V1 kbYRlSxdWR0NWnTofQM6LsFbTZx52Sg= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA4OCBTYWx0ZWRfX3mZMSotAgYtr qaBKYxIfFoL/47gp7RvB3KNvwgj0hPDHET/0FiSTKPlEw0vDlPB4J6Q/vPIJuFY5m0+9ezFEvX+ RqHZLxEj41g4p5F9TWxUhzxgPuabjJbF8paRSbM1bnupLxrqlXdLf/hCUfq6k81O6alSbsb+ft+ C4j7fFhGl1LOcHHfSALiJf+WwRTHNuraogfEWUIkR+Jq8Cd0GYYn4Gm3ygFbl/hjmbfNU3rmJBY AvkYk9nVrHaLCwA+bULtj3Tm5Ie0+2uveQOdM5puN4rMKWvrmNZBR7wMQPsxdFLPQquImFh65ep yQYeT9iVFhdsDGHcEEeVf5zGSZ+zPCLpTlL8FvIo/kiVcvKR3GPFALPvCcEVTYUnwEMZZEmKdNN xKzzwhiG2KE1HGvmOV+H1ZZQWCwQNmMkuyKJVk+l6Sd2dQsRWYWQ2Je3+08+zOzZUCOTjsP+KSl rxm2xTjgXeiAjJvphtA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_04,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 clxscore=1015 spamscore=0 phishscore=0 priorityscore=1501 impostorscore=0 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010088 On kernels with a PAGE_SIZE larger than TRB_SEGMENT_SIZE, xhci_endpoint_init() allocates the ring segments of endpoints that have already been tagged via xhci_sideband_add_endpoint() with dma_alloc_coherent() instead of from the shared xhci->segment_pool, so the buffer reported to the ADSP over QMI is guaranteed to come from a page of its own. xhci_sideband_add_endpoint() must therefore run before the endpoint's transfer ring is first allocated (i.e. before snd_usb_endpoint_prepare() triggers xhci_endpoint_init()) for that allocation to apply. Move the xhci_sideband_add_endpoint() calls out of uaudio_endpoint_setup() and into enable_audio_stream(), before snd_usb_endpoint_prepare() is called for the data and sync endpoints, and unwind them on the new error paths. Now that its only caller tags the endpoint before the ring exists, have xhci_sideband_add_endpoint() return -EBUSY if the endpoint already has a transfer ring, so a sideband client that adds the endpoint too late gets an error instead of a ring that silently came from the shared pool. At that point in the setup sequence dev->ep_in[]/ep_out[] are not yet populated, since the endpoint's altsetting has not been activated, so usb_pipe_endpoint() cannot be used to find the usb_host_endpoint. Add uaudio_find_host_endpoint(), which resolves it directly from the interface's altsetting descriptor table instead. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-sideband.c | 4 +- sound/usb/qcom/qc_audio_offload.c | 158 ++++++++++++++++++++++++++++---------- 2 files changed, 119 insertions(+), 43 deletions(-) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideband.c index d28ff1741166..30c058a5988f 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -225,6 +225,8 @@ EXPORT_SYMBOL_GPL(xhci_sideband_notify_ep_ring_free); * After an endpoint is added the sideband client can get the endpoint transfer * ring buffer by calling xhci_sideband_endpoint_buffer() * + * The endpoint must be added before its transfer ring is allocated. + * * Return: 0 on success, negative error otherwise. */ int @@ -255,7 +257,7 @@ xhci_sideband_add_endpoint(struct xhci_sideband *sb, * and let this function add the endpoint and allocate the ring buffer * with the smallest common DMA mask */ - if (sb->eps[ep_index] || ep->sideband) + if (sb->eps[ep_index] || ep->sideband || ep->ring || ep->new_ring) return -EBUSY; /* diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index b7e17b14feb3..7e8bafd124b0 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -941,6 +941,40 @@ static void uaudio_dev_release(struct kref *kref) wake_up(&dev->disconnect_wq); } +/** + * uaudio_find_host_endpoint() - look up usb_host_endpoint for a snd_usb_endpoint + * @subs: usb substream owning the target snd_usb_endpoint + * @endpoint: sync or data snd_usb_endpoint to resolve + * + * usb_pipe_endpoint() resolves via dev->ep_in[]/ep_out[], which are only + * populated after usb_set_interface() activates the endpoint's altsetting. + * Look the endpoint up directly in that altsetting before preparation instead. + * + * Return: matching usb_host_endpoint, or NULL if not found. + */ +static struct usb_host_endpoint * +uaudio_find_host_endpoint(struct snd_usb_substream *subs, + struct snd_usb_endpoint *endpoint) +{ + struct usb_host_interface *alt; + struct usb_interface *iface; + int i; + + iface = usb_ifnum_to_if(subs->dev, endpoint->iface); + if (!iface) + return NULL; + + alt = usb_altnum_to_altsetting(iface, endpoint->altsetting); + if (!alt) + return NULL; + + for (i = 0; i < alt->desc.bNumEndpoints; i++) + if (alt->endpoint[i].desc.bEndpointAddress == endpoint->ep_num) + return &alt->endpoint[i]; + + return NULL; +} + /** * enable_audio_stream() - enable usb snd endpoints * @subs: usb substream @@ -948,6 +982,7 @@ static void uaudio_dev_release(struct kref *kref) * @channels: number of channels * @cur_rate: sample rate * @datainterval: interval + * @card_num: uadev index * * Opens all USB SND endpoints used for the data interface. This will increment * the USB SND endpoint's opened count. Requests to keep the interface resumed @@ -958,8 +993,9 @@ static void uaudio_dev_release(struct kref *kref) static int enable_audio_stream(struct snd_usb_substream *subs, snd_pcm_format_t pcm_format, unsigned int channels, unsigned int cur_rate, - int datainterval) + int datainterval, unsigned int card_num) { + struct usb_host_endpoint *data_ep = NULL, *sync_ep = NULL; struct snd_pcm_hw_params params; struct snd_usb_audio *chip; struct snd_interval *i; @@ -987,42 +1023,75 @@ static int enable_audio_stream(struct snd_usb_substream *subs, snd_usb_autoresume(chip); ret = snd_usb_hw_params(subs, ¶ms); - if (ret < 0) - goto put_suspend; + if (ret < 0) { + snd_usb_autosuspend(chip); + return ret; + } + + CLASS(snd_usb_lock, pm)(chip); + if (pm.err < 0) { + ret = pm.err; + goto detach_ep; + } + + data_ep = uaudio_find_host_endpoint(subs, subs->data_endpoint); + if (!data_ep) { + dev_err(&subs->dev->dev, "data ep # %d not found\n", + subs->data_endpoint->ep_num); + ret = -ENODEV; + goto detach_ep; + } + + ret = xhci_sideband_add_endpoint(uadev[card_num].sb, data_ep); + if (ret < 0) { + dev_err(&subs->dev->dev, + "failed to add data ep to sideband: %d\n", ret); + goto detach_ep; + } - if (!atomic_read(&chip->shutdown)) { - CLASS(snd_usb_lock, pm)(chip); - if (pm.err < 0) { - ret = pm.err; - goto detach_ep; + if (subs->sync_endpoint) { + sync_ep = uaudio_find_host_endpoint(subs, subs->sync_endpoint); + if (!sync_ep) { + dev_err(&subs->dev->dev, "sync ep # %d not found\n", + subs->sync_endpoint->ep_num); + ret = -ENODEV; + goto remove_data_ep; } - if (subs->sync_endpoint) { - ret = snd_usb_endpoint_prepare(chip, subs->sync_endpoint); - if (ret < 0) - goto detach_ep; + ret = xhci_sideband_add_endpoint(uadev[card_num].sb, sync_ep); + if (ret < 0) { + dev_err(&subs->dev->dev, + "failed to add sync ep to sideband: %d\n", ret); + goto remove_data_ep; } - ret = snd_usb_endpoint_prepare(chip, subs->data_endpoint); + ret = snd_usb_endpoint_prepare(chip, subs->sync_endpoint); if (ret < 0) - goto detach_ep; - - dev_dbg(uaudio_qdev->data->dev, - "selected %s iface:%d altsetting:%d datainterval:%dus\n", - subs->direction ? "capture" : "playback", - subs->cur_audiofmt->iface, subs->cur_audiofmt->altsetting, - (1 << subs->cur_audiofmt->datainterval) * - (subs->dev->speed >= USB_SPEED_HIGH ? - BUS_INTERVAL_HIGHSPEED_AND_ABOVE : - BUS_INTERVAL_FULL_SPEED)); + goto remove_sync_ep; } + ret = snd_usb_endpoint_prepare(chip, subs->data_endpoint); + if (ret < 0) + goto remove_sync_ep; + + dev_dbg(uaudio_qdev->data->dev, + "selected %s iface:%d altsetting:%d datainterval:%dus\n", + subs->direction ? "capture" : "playback", + subs->cur_audiofmt->iface, subs->cur_audiofmt->altsetting, + (1 << subs->cur_audiofmt->datainterval) * + (subs->dev->speed >= USB_SPEED_HIGH ? + BUS_INTERVAL_HIGHSPEED_AND_ABOVE : + BUS_INTERVAL_FULL_SPEED)); + return 0; +remove_sync_ep: + if (sync_ep) + xhci_sideband_remove_endpoint(uadev[card_num].sb, sync_ep); +remove_data_ep: + xhci_sideband_remove_endpoint(uadev[card_num].sb, data_ep); detach_ep: snd_usb_hw_free(subs); - -put_suspend: snd_usb_autosuspend(chip); return ret; @@ -1140,20 +1209,12 @@ uaudio_endpoint_setup(struct snd_usb_substream *subs, memcpy(ep_desc, &ep->desc, sizeof(ep->desc)); - ret = xhci_sideband_add_endpoint(uadev[card_num].sb, ep); - if (ret < 0) { - dev_err(&subs->dev->dev, - "failed to add data ep to sec intr: %d\n", ret); - ret = -ENODEV; - goto exit; - } - sgt = xhci_sideband_get_endpoint_buffer(uadev[card_num].sb, ep); if (!sgt) { dev_err(&subs->dev->dev, "failed to get data ep ring address: %d\n", ret); ret = -ENODEV; - goto remove_ep; + goto exit; } pg = sg_page(sgt->sgl); @@ -1177,8 +1238,6 @@ uaudio_endpoint_setup(struct snd_usb_substream *subs, clear_pa: mem_info->dma = 0; -remove_ep: - xhci_sideband_remove_endpoint(uadev[card_num].sb, ep); exit: return ret; } @@ -1519,14 +1578,10 @@ static int prepare_qmi_response(struct snd_usb_substream *subs, uaudio_iommu_unmap(MEM_XFER_RING, IOVA_MASK(resp->xhci_mem_info.tr_sync.iova), PAGE_SIZE, PAGE_SIZE); - xhci_sideband_remove_endpoint(uadev[card_num].sb, - usb_pipe_endpoint(subs->dev, subs->sync_endpoint->pipe)); } drop_data_ep: uaudio_iommu_unmap(MEM_XFER_RING, IOVA_MASK(resp->xhci_mem_info.tr_data.iova), PAGE_SIZE, PAGE_SIZE); - xhci_sideband_remove_endpoint(uadev[card_num].sb, - usb_pipe_endpoint(subs->dev, subs->data_endpoint->pipe)); return ret; } @@ -1637,11 +1692,30 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, ret = enable_audio_stream(subs, map_pcm_format(req_msg->audio_format), req_msg->number_of_ch, req_msg->bit_rate, - datainterval); + datainterval, pcm_card_num); - if (!ret) + if (!ret) { ret = prepare_qmi_response(subs, req_msg, &resp, info_idx); + if (ret < 0) { + struct xhci_sideband *sb = uadev[pcm_card_num].sb; + + if (subs->sync_endpoint) { + ep = usb_pipe_endpoint(subs->dev, + subs->sync_endpoint->pipe); + if (ep) + xhci_sideband_remove_endpoint(sb, ep); + } + + ep = usb_pipe_endpoint(subs->dev, + subs->data_endpoint->pipe); + if (ep) + xhci_sideband_remove_endpoint(sb, ep); + + disable_audio_stream(subs); + } + } + if (ret < 0) { guard(mutex)(&chip->mutex); subs->opened = 0; -- 2.43.0