Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3083612rdb; Tue, 6 Feb 2024 06:50:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFqilhHsD6pSq6Xc8G4Ot3YRhLE7lA05fIHLm0ioG/Z+VQjOjmhScPuTX427zR5cQUqaTU X-Received: by 2002:aa7:df86:0:b0:560:545:83f5 with SMTP id b6-20020aa7df86000000b00560054583f5mr1953596edy.9.1707231041982; Tue, 06 Feb 2024 06:50:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707231041; cv=pass; d=google.com; s=arc-20160816; b=S0YdDyaWOUSj5qC3ru6RRdWyTc/j5udLvv7Jnc1E3+e2TOb18aUQN2vyvpVShcu2+z RIXP55XLpas/OWaR5baAGM8DzIQeEprAh/MFYemmR31ybsXhlbW4tMbN+z5mFGsd/mrE 2Mmq28viLxc38jwpP6vXGPJOWQUY2VB0sDPFu3gwTjKP+QtMR27PWPOaZAqFznFisutc SlEdMGVhww7nPj3/Jf3n+s5IO6iIc8QfKXNemQfUMyGubDF0SIytTbqPcI5E2kA69j63 GG/NCBFnT5B4089HHRokx+pvQYrQydgJkowYUdTSeDTiApdz1GMiBQBEIXQ7qv2Z49Ay b1Dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=N15GoEdIqUEu9Oo46IGiVeEzEj2u20TI4MkgtTt5wL4=; fh=xV2g/2Q52RHe6m9loKz0uASaKAMd8Hl/MifzuhgNmqY=; b=oXZenwh8dGmGkLNAzXz0Wsb4OQTcI3YxqFMdDbG1lvQt49Pcs2ZPDrpptWXM/7TUdt XCN6XOAa/usLrVI9dywMpCN1F3Vmx8JSIYBTz/Xr8bawy0aNuK/uEyHw6Y9MdfPpRvxi zjpQ+p73FNFEIlfNcBLaiHLj9PD0AggqjxAgEd9SKRraDpt9rQwnZg508AHL6dOzun6O l38npEl7ZMGxuAG0Yf/jI6D9/ixcPF/V2C5iI663GrjOwAOrdcVoKiEm9yzgjldnieGY m0ttQ5GpKUY6FRW/yEJIoCx8uplfH3I+/wN8A1tvLnppAv1R/oDEPf/MXw3n+ld0emcT cQ4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kLFOOydV; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-55142-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55142-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org X-Forwarded-Encrypted: i=1; AJvYcCWkcN/WIIn+T6MZVnFuj6Jm5+ZSdFqf5HHqO/q3aq7Rco9NB8rxqn1MFYVzyKDKmAa1ieiutt1L4UmDZx13T9k38VSM4mkUN6ldIWVU4A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d13-20020a50f68d000000b005606504da57si1194636edn.172.2024.02.06.06.50.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 06:50:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55142-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kLFOOydV; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-55142-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55142-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B844A1F26FA8 for ; Tue, 6 Feb 2024 14:50:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1D67132C3B; Tue, 6 Feb 2024 14:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kLFOOydV" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7ED31E4BE; Tue, 6 Feb 2024 14:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707231024; cv=none; b=ZLq5JClHXDOvF1O4Phd791iZAht+njlIPCDlOY+ehsD3ylI/X/0mQ+ItgNPZcfvDz7O6mao99iddl8yNnfRrhstupKLT5oFcsOnu1DLu2EauVPobJm14cmodz+2WaJPW27tGZpxGqiYlvfvhSD6ieSF7dcQPdgsT02SAvkZuuWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707231024; c=relaxed/simple; bh=TRNOZ2E0jVFr1j4Jk3WeOB19Tmkl0WCO11cXpH5xx0c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uLehfM0Tm/ri9VGKbGbGne2qY3konLpMXzCtKnFbP9yzWeW0U0FzFJxCWO66irpNJkCcjfDyygqDAwn/qIP+50BiBOmG8pjNAM8SehKqoX9T+a3NaDuqpyaE7Bji0aCzRlMDD5fC6JW6TKxyuWWVGRGTxU0xKrVXzjiyJVE053w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kLFOOydV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 742AAC433C7; Tue, 6 Feb 2024 14:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1707231024; bh=TRNOZ2E0jVFr1j4Jk3WeOB19Tmkl0WCO11cXpH5xx0c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kLFOOydVz8hY/tZlvFGGUr5yxRLIh5a3MMj5zIRocdMkLDC1jdALkpy9OA3M9F8lD uRpBnMXQLY+8ovJ86Mu/N+WBHiVZCawbZRCXM749gkLpVYkyUjNoqP4OZx2B7X+6le 95uqhpXCNWzr+Hy9rLJ6CQwMVmoMMdIisEZbF31o= Date: Tue, 6 Feb 2024 14:50:21 +0000 From: Greg KH To: Takashi Iwai Cc: Wesley Cheng , srinivas.kandagatla@linaro.org, mathias.nyman@intel.com, perex@perex.cz, conor+dt@kernel.org, corbet@lwn.net, lgirdwood@gmail.com, andersson@kernel.org, krzysztof.kozlowski+dt@linaro.org, Thinh.Nguyen@synopsys.com, broonie@kernel.org, bgoswami@quicinc.com, tiwai@suse.com, robh+dt@kernel.org, konrad.dybcio@linaro.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-sound@vger.kernel.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-doc@vger.kernel.org, alsa-devel@alsa-project.org Subject: Re: [PATCH v13 32/53] ALSA: usb-audio: Check for support for requested audio format Message-ID: <2024020617-limb-name-f852@gregkh> References: <20240203023645.31105-1-quic_wcheng@quicinc.com> <20240203023645.31105-33-quic_wcheng@quicinc.com> <87wmrhvir7.wl-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wmrhvir7.wl-tiwai@suse.de> On Tue, Feb 06, 2024 at 02:12:44PM +0100, Takashi Iwai wrote: > On Sat, 03 Feb 2024 03:36:24 +0100, > Wesley Cheng wrote: > > > > Allow for checks on a specific USB audio device to see if a requested PCM > > format is supported. This is needed for support when playback is > > initiated by the ASoC USB backend path. > > > > Signed-off-by: Wesley Cheng > > Just cosmetic: > > > +struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, > > + struct snd_pcm_hw_params *params, int direction) > > +{ > > + struct snd_usb_audio *chip; > > + struct snd_usb_substream *subs; > > + struct snd_usb_stream *as; > > + const struct audioformat *fmt; > > + > > + /* > > + * Register mutex is held when populating and clearing usb_chip > > + * array. > > + */ > > + mutex_lock(®ister_mutex); > > + chip = usb_chip[card_idx]; > > + if (!chip) { > > + mutex_unlock(®ister_mutex); > > + return NULL; > > + } > > + > > + if (enable[card_idx]) { > > + list_for_each_entry(as, &chip->pcm_list, list) { > > + subs = &as->substream[direction]; > > + fmt = snd_usb_find_substream_format(subs, params); > > + if (fmt) { > > + mutex_unlock(®ister_mutex); > > + return as; > > + } > > + } > > + } > > + mutex_unlock(®ister_mutex); > > I prefer having the single lock/unlock call pair, e.g. > > struct snd_usb_stream *as, *ret; > > ret = NULL; > mutex_lock(®ister_mutex); > chip = usb_chip[card_idx]; > if (chip && enable[card_idx]) { > list_for_each_entry(as, &chip->pcm_list, list) { > subs = &as->substream[direction]; > if (snd_usb_find_substream_format(subs, params)) { > ret = as; > break; > } > } > } > mutex_unlock(®ister_mutex); > return ret; > } > > In this case, we shouldn't reuse "as" for the return value since it > can be non-NULL after the loop end. Why not just use guard(mutex) for this, making it all not an issue? thanks, greg k-h