From nobody Thu Apr 9 14:09:02 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32228292B2E for ; Mon, 9 Mar 2026 02:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773022938; cv=none; b=XJEcSFoRmLf2N5J3UNCr1OyZZliD8YKGOPQcyq5adrq0fTXApF0g+t0AM7htnB02JFcR8t7BXnPlpj7axf/ccqgVq9Rc7PwU5JPU8u2wX9YC9bbFEY3fzdF2RcHvf0qJWIrqHYyaSnwW17v+jG0sf/MuK1vLDus2QLCFS/ufg9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773022938; c=relaxed/simple; bh=sfhKlOxhZjp27RRqyMOv5tQbb25tvaGuKH9jjcuerK8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oQSImUW9kL9CnNKt1HizL0oH0y67Bmdzp9RggnD0KI84vdZMF/438HI7Rvt2ABbE+UEu0U9pYEISOGBfINADkSP3d29aJkwos5PB9sZ6XTb77tItobZOrwkqZeOdwzYVl6DT+qkgL5AZHN7ys8bcDDFVSupeqyh69ijKbsPhZ5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qXS0xK/H; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qXS0xK/H" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b6ce1b57b9cso8561987a12.1 for ; Sun, 08 Mar 2026 19:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773022936; x=1773627736; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gplv2Tex9lazNCSIePgQz/7GHAFcH+CmqLMfgw0rRa0=; b=qXS0xK/H+4hXaFLUlZ8x87PPHpUbo46YLYLBWMcdL9kyLAofzbPujHJCCKYCmfDIKI BAaWPJKtf0PDXEyvBUJH3E98gWq9K6EfaAmpcYtIPoWKoQhKlNurghHkYy/OV2bqExfV Eb1lGEnpPVGw1Y0vZ7+dIz611n+QcCpX/phanCnjfZbr22m7H9EUpzJHDj5Q6gH7kL88 A90UAYwwWr2fp4/MjdBikNAwFpE/NM8XRJeElQ8G+7xJJyXyZ0KIXrNNAtAcOBwia6an vbOgLueVCmlSlNPm6E/SG7w/kjC/vBZNaJsjdqaz6fZ+1h5zHDx+ebWoCwIHouO8igbE OjIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773022936; x=1773627736; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gplv2Tex9lazNCSIePgQz/7GHAFcH+CmqLMfgw0rRa0=; b=TiFvFJtnt6ah3oJGDOYlgaKAJNhBFeYUa3GvXwfDgDT1YuOhSoOoTxPdmmO0MKYPZL QJAXtDpnYwmvr75w9OJNE2nY2fQmLLt38usJPjHJQKJUvRc9z0ohOw4Y7Q750YKkrUCW oblTuDfxF+ezSmTYVCS9hlDuitI0Q3KZuFMKguMsXLP2AxBjelVQEmYWjC5vF2sKMN6h HKIdL9GAkH7ZwH6mMdLXG1rZvAnNr+KzfC6rVf7sYlYevOZwZCTzDQ6KG7balOnQW28O B7WZuuZEpAjEyV3WicmYLQ4j/Kk57s1VKRzTOGCShTsz1Zb3YR4nOH5GcrzAl5MNp9dc FPJg== X-Forwarded-Encrypted: i=1; AJvYcCXY4ScJzAQYicpto+wulVRbj+e4qwCs32Bsm2Mdifp9kSF83oNR+e+OH02mpKsFbOiR9zvBC5dSVJY6xDs=@vger.kernel.org X-Gm-Message-State: AOJu0YxZZrqz3oggazVenMIGUMQKHe3+bTpg2bzgphNtWGdgzMMyyRB6 bPgV9fnJO6811wQHpO1JN6W+uNDaQp3DZL8KMTCYsGaddaSIHEuVhn9lgWVklh4l935X+35OtFv hRI3qGkdcbkeV4VBXBg== X-Received: from pliy14.prod.google.com ([2002:a17:903:3d0e:b0:2ae:42de:7ed4]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f64e:b0:2ae:3ab7:1545 with SMTP id d9443c01a7336-2ae82505e81mr96587345ad.43.1773022936417; Sun, 08 Mar 2026 19:22:16 -0700 (PDT) Date: Mon, 9 Mar 2026 02:22:05 +0000 In-Reply-To: <20260309022205.28136-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260309022205.28136-1-guanyulin@google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260309022205.28136-3-guanyulin@google.com> Subject: [PATCH v2 2/2] ALSA: usb: qcom: manage offload device usage From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, perex@perex.cz, tiwai@suse.com, quic_wcheng@quicinc.com, broonie@kernel.org, arnd@arndb.de, christophe.jaillet@wanadoo.fr, xiaopei01@kylinos.cn, wesley.cheng@oss.qualcomm.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Guan-Yu Lin , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Qualcomm USB audio offload driver currently does not report its offload activity to the USB core. This prevents the USB core from properly tracking active offload sessions, which could allow the device to auto-suspend while audio offloading is in progress. Integrate usb_offload_get() and usb_offload_put() calls into the offload stream setup and teardown paths. Specifically, call usb_offload_get() when initializing the event ring and usb_offload_put() when freeing it. Since the updated usb_offload_get() and usb_offload_put() APIs require the caller to hold the USB device lock, add the necessary device locking in handle_uaudio_stream_req() and qmi_stop_session() to satisfy this requirement. Cc: stable@vger.kernel.org Fixes: ef82a4803aab ("xhci: sideband: add api to trace sideband usage") Signed-off-by: Guan-Yu Lin --- sound/usb/qcom/qc_audio_offload.c | 102 ++++++++++++++++++------------ 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.c index cfb30a195364..1da243662327 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -699,6 +699,7 @@ static void uaudio_event_ring_cleanup_free(struct uaudi= o_dev *dev) uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE); xhci_sideband_remove_interrupter(uadev[dev->chip->card->number].sb); + usb_offload_put(dev->udev); } } =20 @@ -750,6 +751,7 @@ static void qmi_stop_session(void) struct snd_usb_substream *subs; struct usb_host_endpoint *ep; struct snd_usb_audio *chip; + struct usb_device *udev; struct intf_info *info; int pcm_card_num; int if_idx; @@ -791,8 +793,13 @@ static void qmi_stop_session(void) disable_audio_stream(subs); } atomic_set(&uadev[idx].in_use, 0); - guard(mutex)(&chip->mutex); - uaudio_dev_cleanup(&uadev[idx]); + + udev =3D uadev[idx].udev; + if (udev) { + guard(device)(&udev->dev); + guard(mutex)(&chip->mutex); + uaudio_dev_cleanup(&uadev[idx]); + } } } =20 @@ -1183,11 +1190,15 @@ static int uaudio_event_ring_setup(struct snd_usb_s= ubstream *subs, er_pa =3D 0; =20 /* event ring */ + ret =3D usb_offload_get(subs->dev); + if (ret < 0) + goto exit; + ret =3D xhci_sideband_create_interrupter(uadev[card_num].sb, 1, false, 0, uaudio_qdev->data->intr_num); if (ret < 0) { dev_err(&subs->dev->dev, "failed to fetch interrupter\n"); - goto exit; + goto put_offload; } =20 sgt =3D xhci_sideband_get_event_buffer(uadev[card_num].sb); @@ -1219,6 +1230,8 @@ static int uaudio_event_ring_setup(struct snd_usb_sub= stream *subs, mem_info->dma =3D 0; remove_interrupter: xhci_sideband_remove_interrupter(uadev[card_num].sb); +put_offload: + usb_offload_put(subs->dev); exit: return ret; } @@ -1483,6 +1496,7 @@ static int prepare_qmi_response(struct snd_usb_substr= eam *subs, uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE); free_sec_ring: xhci_sideband_remove_interrupter(uadev[card_num].sb); + usb_offload_put(subs->dev); drop_sync_ep: if (subs->sync_endpoint) { uaudio_iommu_unmap(MEM_XFER_RING, @@ -1528,6 +1542,7 @@ static void handle_uaudio_stream_req(struct qmi_handl= e *handle, u8 pcm_card_num; u8 pcm_dev_num; u8 direction; + struct usb_device *udev =3D NULL; int ret =3D 0; =20 if (!svc->client_connected) { @@ -1597,50 +1612,53 @@ static void handle_uaudio_stream_req(struct qmi_han= dle *handle, =20 uadev[pcm_card_num].ctrl_intf =3D chip->ctrl_intf; =20 - if (req_msg->enable) { - ret =3D enable_audio_stream(subs, - map_pcm_format(req_msg->audio_format), - req_msg->number_of_ch, req_msg->bit_rate, - datainterval); - - if (!ret) - ret =3D prepare_qmi_response(subs, req_msg, &resp, - info_idx); - if (ret < 0) { - guard(mutex)(&chip->mutex); - subs->opened =3D 0; - } - } else { - info =3D &uadev[pcm_card_num].info[info_idx]; - if (info->data_ep_pipe) { - ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, - info->data_ep_pipe); - if (ep) { - xhci_sideband_stop_endpoint(uadev[pcm_card_num].sb, - ep); - xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, - ep); + udev =3D subs->dev; + scoped_guard(device, &udev->dev) { + if (req_msg->enable) { + ret =3D enable_audio_stream(subs, + map_pcm_format(req_msg->audio_format), + req_msg->number_of_ch, req_msg->bit_rate, + datainterval); + + if (!ret) + ret =3D prepare_qmi_response(subs, req_msg, &resp, + info_idx); + if (ret < 0) { + guard(mutex)(&chip->mutex); + subs->opened =3D 0; + } + } else { + info =3D &uadev[pcm_card_num].info[info_idx]; + if (info->data_ep_pipe) { + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->data_ep_pipe); + if (ep) { + xhci_sideband_stop_endpoint(uadev[pcm_card_num].sb, + ep); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, + ep); + } + + info->data_ep_pipe =3D 0; } =20 - info->data_ep_pipe =3D 0; - } - - if (info->sync_ep_pipe) { - ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, - info->sync_ep_pipe); - if (ep) { - xhci_sideband_stop_endpoint(uadev[pcm_card_num].sb, - ep); - xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, - ep); + if (info->sync_ep_pipe) { + ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->sync_ep_pipe); + if (ep) { + xhci_sideband_stop_endpoint(uadev[pcm_card_num].sb, + ep); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, + ep); + } + + info->sync_ep_pipe =3D 0; } =20 - info->sync_ep_pipe =3D 0; + disable_audio_stream(subs); + guard(mutex)(&chip->mutex); + subs->opened =3D 0; } - - disable_audio_stream(subs); - guard(mutex)(&chip->mutex); - subs->opened =3D 0; } =20 response: --=20 2.53.0.473.g4a7958ca14-goog