From nobody Fri Dec 19 17:33:08 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB4D2C04A95 for ; Sat, 22 Oct 2022 11:22:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230354AbiJVLWI (ORCPT ); Sat, 22 Oct 2022 07:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbiJVLVo (ORCPT ); Sat, 22 Oct 2022 07:21:44 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94245238244; Sat, 22 Oct 2022 03:50:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id F1198CE2CA3; Sat, 22 Oct 2022 07:50:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10EE1C433D6; Sat, 22 Oct 2022 07:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425023; bh=mVlXKDyloWHczG4w8BODEuzPi+MoNX5tHp/3T8IM120=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sh0bSzyHHMKUv5eCZ6JbbRarLP+IbqlW73NGf8cvWSG4pY2XyhCZgPEt5x32l8xuq +1zajEQn9VOqCiPXRDpyRTwo9LhLR+ijuNIWp952EVwiGhgbgFDRx/GEpO7Uh3dCM/ NzBQyirJoVLHkwe/pZ1m2IbFdoEQsHMA8R7MjI24= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Sasha Levin Subject: [PATCH 5.19 333/717] ALSA: usb-audio: Properly refcounting clock rate Date: Sat, 22 Oct 2022 09:23:32 +0200 Message-Id: <20221022072509.781401249@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Takashi Iwai [ Upstream commit 9a737e7f8b371e97eb649904276407cee2c9cf30 ] We fixed the bug introduced by the patch for managing the shared clocks at the commit 809f44a0cc5a ("ALSA: usb-audio: Clear fixed clock rate at closing EP"), but it was merely a workaround. By this change, the clock reference rate is cleared at each EP close, hence the still remaining EP may need a re-setup of rate unnecessarily. This patch introduces the proper refcounting for the clock reference object so that the clock setup is done only when needed. Fixes: 809f44a0cc5a ("ALSA: usb-audio: Clear fixed clock rate at closing EP= ") Fixes: c11117b634f4 ("ALSA: usb-audio: Refcount multiple accesses on the si= ngle clock") Link: https://lore.kernel.org/r/20220920181126.4912-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/usb/endpoint.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -39,6 +39,7 @@ struct snd_usb_iface_ref { struct snd_usb_clock_ref { unsigned char clock; atomic_t locked; + int opened; int rate; struct list_head list; }; @@ -802,6 +803,7 @@ snd_usb_endpoint_open(struct snd_usb_aud ep =3D NULL; goto unlock; } + ep->clock_ref->opened++; } =20 ep->cur_audiofmt =3D fp; @@ -925,8 +927,10 @@ void snd_usb_endpoint_close(struct snd_u endpoint_set_interface(chip, ep, false); =20 if (!--ep->opened) { - if (ep->clock_ref && !atomic_read(&ep->clock_ref->locked)) - ep->clock_ref->rate =3D 0; + if (ep->clock_ref) { + if (!--ep->clock_ref->opened) + ep->clock_ref->rate =3D 0; + } ep->iface =3D 0; ep->altsetting =3D 0; ep->cur_audiofmt =3D NULL; @@ -1633,8 +1637,7 @@ void snd_usb_endpoint_stop(struct snd_us WRITE_ONCE(ep->sync_source->sync_sink, NULL); stop_urbs(ep, false, keep_pending); if (ep->clock_ref) - if (!atomic_dec_return(&ep->clock_ref->locked)) - ep->clock_ref->rate =3D 0; + atomic_dec(&ep->clock_ref->locked); } }