From nobody Fri Oct 17 10:31:38 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 DBB65C433FE for ; Wed, 19 Oct 2022 09:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232403AbiJSJGE (ORCPT ); Wed, 19 Oct 2022 05:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbiJSJEV (ORCPT ); Wed, 19 Oct 2022 05:04:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B59A175A2; Wed, 19 Oct 2022 01:57:30 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 10A77617E1; Wed, 19 Oct 2022 08:55:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 248F9C433C1; Wed, 19 Oct 2022 08:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169758; bh=mVlXKDyloWHczG4w8BODEuzPi+MoNX5tHp/3T8IM120=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hA2GAtk56ZECZtxKMh8abaJKz324C/BK7rFfZC1iAcnCkNeUnUlm8iKLaIW+5jxPg 7QtODXMUlUAPUMRa7bkhCCOECsPVuGuedUMd7a33KRxGDh0GdvZdTT8TXyK4xeHWxW JYwXXJdfSx2SKz81UNxvkQKbij9C5XHSYRjnlZX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Sasha Levin Subject: [PATCH 6.0 397/862] ALSA: usb-audio: Properly refcounting clock rate Date: Wed, 19 Oct 2022 10:28:04 +0200 Message-Id: <20221019083307.475460304@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@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); } }