Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3109117rdb; Tue, 6 Feb 2024 07:26:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+UG0yc8LeR8WIXLXwEhb28bSRkHmjj9+u5aZErNCYxzUymQccpNipoon9ABCX9dPEbqdh X-Received: by 2002:a05:6e02:cc5:b0:363:b805:fcb6 with SMTP id c5-20020a056e020cc500b00363b805fcb6mr2222355ilj.28.1707233195308; Tue, 06 Feb 2024 07:26:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707233195; cv=pass; d=google.com; s=arc-20160816; b=k7syt1h5m0eqVqyT4BpOR6/1a6RVpSnlyiJwFe/dnBZIlvcxx+voPTumFSMDkMCjcc CYg1VJEGyn87080ysVRigtqVcwNqoqWdv3joyzZv/j5aHpVIV3TpvUESqP68QJsCOSNj fZORcBL373fYgfRnMKYoWOKCawjWTVWw9zp3hGgBnHy5wMQd+P6n0OFCaQauxlYn0B80 T/vuVgJYTilXDE96Qx2xpRQg7nkiJm/nCKsJCyVl3aF9h9nD5RS7lkFzsBCGoABrb9oK UkwmBuLkX7rlvO+IX7L1PGrSQTAAyL5s5kwx/zCrtWcf7ZSnGdXhSt8CRgQq3arsZAIW U2Ww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=AEGImGG0Ff6z25ekPfLY3b5KTypKA7hNz0dlcxRASQs=; fh=mfX2Wds3mv+vfVAKyeFdJgRQr6iMngF7T+erEN/DoMw=; b=zjuBRnOAgmKCafsYCF4DqAEVBrUn+RIg0+AxrSiN2X7SaDjiBwy+YumQbh/v6YFj9w X1Rqrv1Xgcy/OUXPMbkOpm9eGBP+NN0R5wqa/X5kQEOffrGb0ku9ybs1YheuslMJochA kuSdJzM9O0rudhuoxXcgWx+8AvGpXorJU7OMn/M4S/9xwBDfZ+WdXyQuuIDI/PLO7hOB PP5VGtf1Yx1UmywPnKyvNjQZle7XUFzrY1Muml3J1vXTvfO2chGPeXZica9vmUNXTGXA nYpwI/mg60UEu0zb7Q+UIsdD2aoIVn5ku84p6ufdPIH+0B+qRmoqnmOHjLkQsdvJFwPR K51A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Gd8XC4jH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=KlIBRPwB; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Gd8XC4jH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-55150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=1; AJvYcCX09LbUafg6p71DtbMZryrZdh7j0bP9kvmmJI0A1qJNvstQm7pVXE/QMoNIQFzpfToSxp7W0tAlldLyOmXfLRXivqxZ91Ob3MC7DQ3hvg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f13-20020a63dc4d000000b005c279da45f1si1863362pgj.566.2024.02.06.07.26.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 07:26:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Gd8XC4jH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=KlIBRPwB; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Gd8XC4jH; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-55150-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55150-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2F172B2F473 for ; Tue, 6 Feb 2024 14:55:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84106133401; Tue, 6 Feb 2024 14:53:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Gd8XC4jH"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="KlIBRPwB"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Gd8XC4jH"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="KlIBRPwB" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 C75FD131E40; Tue, 6 Feb 2024 14:53:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707231228; cv=none; b=bOheV+cEtcACrHeEY02/BeBb7Z6fSETI7TucQOUvqWFGBBg3pOjpVR+ojav6qWVyFZyTwcYLWSc0vMI/RN0b5d8oVI0OoGTRzjNWHNHAg9ipLmk7JDm3iyXIE6vMBP6co8gDoaJaauf3lWL7ysRccaRmhACV9ofWSkkHvPM+x5s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707231228; c=relaxed/simple; bh=6imiZNz13DtNsVm7OhjM91Tu6n6+upch3RjcbTaBXbo=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=Xo0s8OlMXUSr3/VFrf7GUAHVWrnDJ5Sg36Im770oJdFgQcpZRi1bKj6kMO3cJ9CtzrlPOkZo1gsp9EXDq0oS68sB8AX10gRo9ulbSRXVVaRCcXnP6M5HvYo7JqUKPqY4baLaVev3V4DXwDjYOQZxczQW7jLuIaInVyhRbaYdMBI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Gd8XC4jH; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=KlIBRPwB; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Gd8XC4jH; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=KlIBRPwB; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 890D8220AD; Tue, 6 Feb 2024 14:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707231224; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AEGImGG0Ff6z25ekPfLY3b5KTypKA7hNz0dlcxRASQs=; b=Gd8XC4jHmAO2wIh9frwlto9XxCy5MYvJewPaeif1JTc76zhIL49XXS+ftX3Nrk5y5F+0Ib kb8zevdT/b2sOVr+QUkTw6EwrWVxuckdhiafBvDzV0N9OaXfGzC/QBrFNDJJRGXPG3Gu2Q 6w5NhzyGSL+gLom0GAbnm4gRoV5pe20= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707231224; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AEGImGG0Ff6z25ekPfLY3b5KTypKA7hNz0dlcxRASQs=; b=KlIBRPwBqPNyqo9m1MMtV8YIVgZTYkqY4/WYuTbYOsetUNgX+vC8/51oPkoo8pHPgzYyZX CNIYGmYF15FKqCCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707231224; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AEGImGG0Ff6z25ekPfLY3b5KTypKA7hNz0dlcxRASQs=; b=Gd8XC4jHmAO2wIh9frwlto9XxCy5MYvJewPaeif1JTc76zhIL49XXS+ftX3Nrk5y5F+0Ib kb8zevdT/b2sOVr+QUkTw6EwrWVxuckdhiafBvDzV0N9OaXfGzC/QBrFNDJJRGXPG3Gu2Q 6w5NhzyGSL+gLom0GAbnm4gRoV5pe20= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707231224; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AEGImGG0Ff6z25ekPfLY3b5KTypKA7hNz0dlcxRASQs=; b=KlIBRPwBqPNyqo9m1MMtV8YIVgZTYkqY4/WYuTbYOsetUNgX+vC8/51oPkoo8pHPgzYyZX CNIYGmYF15FKqCCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 46FC3139D8; Tue, 6 Feb 2024 14:53:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id K0myEPhHwmUiVwAAD6G6ig (envelope-from ); Tue, 06 Feb 2024 14:53:44 +0000 Date: Tue, 06 Feb 2024 15:53:43 +0100 Message-ID: <87sf25wsnc.wl-tiwai@suse.de> From: Takashi Iwai To: Greg KH 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 In-Reply-To: <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> <2024020617-limb-name-f852@gregkh> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Gd8XC4jH; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=KlIBRPwB X-Spamd-Result: default: False [2.11 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; BAYES_HAM(-0.08)[63.26%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[dt]; MIME_GOOD(-0.10)[text/plain]; R_RATELIMIT(0.00)[to_ip_from(RLe67txhfobum3fqdb5xx8e3au)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[23]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[quicinc.com,linaro.org,intel.com,perex.cz,kernel.org,lwn.net,gmail.com,synopsys.com,suse.com,vger.kernel.org,alsa-project.org]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: 2.11 X-Rspamd-Queue-Id: 890D8220AD X-Spam-Level: ** X-Spam-Flag: NO X-Spamd-Bar: ++ On Tue, 06 Feb 2024 15:50:21 +0100, Greg KH wrote: > > 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? Heh, it's too new ;) That should work gracefully, yes. Takashi