Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4283784rwo; Tue, 25 Jul 2023 03:52:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGwNF9yHRdqkzWKYMPe/7pBIKk9dxdMaTiJZpkLD7SaH56In2Ksi5awQnmeKxur514FilYn X-Received: by 2002:a05:6a00:1817:b0:673:5d1e:6657 with SMTP id y23-20020a056a00181700b006735d1e6657mr10080715pfa.7.1690282359367; Tue, 25 Jul 2023 03:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690282359; cv=none; d=google.com; s=arc-20160816; b=IiAAI+e830hSXDVmCJ8TfXD5zQkxXGFU33LFk0z4PsAzzmJ4j289idnfr/Fevv/8r/ vFUs1p4PtFcvmpthwc2JGxsN7OSBtxUfNJnxf0SzslbpRI3RVff+CLufX7LbLpfYjZAU kbRYdRRBE3W40GcZSkJDn+taWy5N2zGOA7MWFDj8rDCcSk8eA/zQjO7TPyoHHqwb/tZC lx41HmKem8xo7T9T/aQ+z+u+zCMmGy+Q2owLqRWu2kzj0rkvisVCTYovsdqN/w9iiMvZ BgYUdjfEArNt9tfBuSsKoc6+MZSehuk0QwlMUp5HZGFuWLI0m72aVovfLB1SOC+b6Mr9 x1mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=dlmzFCGGYQOm0hww9I94vhrQZ+jHyAZdm6rRpIEjF90=; fh=myr10mAckP/W0E+45D/DfW7X6PBrHKhok0OiVl7ozZs=; b=zrK6QZXOofOiMt1mX9Ar4nN9ikRH4CgKmg0eEBS5dnucX/ScXRZ23cios6lx47dzGl dOzPLkJVCA/hEQy2NbMrBMG80JWkDTTq1Hg21nTRqUYECPYNvKm8HTDJlKFNqAXVJC7B QX3atpSblIwrPjWodIrE+pKfzAhv2hHcxJ0Yo13+uldioBT430amHCxMGAnXmUY3TKxL EyL6I/PgRj8tI03jFpTsUs1Abcx0z4ygkt44ecxOCdHcn3TYHhMMi1jXFOFJmDefO7m6 Z4rlHBNl9cGJkQL1m6OovuxQy81G8MmNNQaA4A3Yq1stKEo6IHKb9kTmXZt3GSYJwOHX nMVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=PRo+S7Rm; dkim=neutral (no key) header.i=@suse.de header.b=YgzmBwsI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w30-20020a63af1e000000b0055a5434684bsi655388pge.106.2023.07.25.03.52.25; Tue, 25 Jul 2023 03:52:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=PRo+S7Rm; dkim=neutral (no key) header.i=@suse.de header.b=YgzmBwsI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233376AbjGYJbJ (ORCPT + 99 others); Tue, 25 Jul 2023 05:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233332AbjGYJax (ORCPT ); Tue, 25 Jul 2023 05:30:53 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5A92129; Tue, 25 Jul 2023 02:28:51 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4325821D19; Tue, 25 Jul 2023 09:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690277248; 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=dlmzFCGGYQOm0hww9I94vhrQZ+jHyAZdm6rRpIEjF90=; b=PRo+S7RmJ6Cc6bdhtacBMBVPU0SqboE3Y7rpFnOiK1Mq9XIrUJP3fSFbZsy9kfFcUwujD5 WAvLiRQ8NOGIh1o3Ewx9MCTnAAf/Ygz6kKruXb7xNcO4nHY6HHOCwUzydKccfWZjjhOAnQ D5GnYf0ugpBwpFhA0yMmZBBMuaJsaq0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690277248; 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=dlmzFCGGYQOm0hww9I94vhrQZ+jHyAZdm6rRpIEjF90=; b=YgzmBwsIwCX1597u5bMv1SYnvoyq1qC84nN2STKtgbnSxaX9bLFt9yxYC1ntPATTKOE1F2 uFivkNfbgRwy6UCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AE02A13487; Tue, 25 Jul 2023 09:27:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GCooKX+Vv2RgWQAAMHmgww (envelope-from ); Tue, 25 Jul 2023 09:27:27 +0000 Date: Tue, 25 Jul 2023 11:27:27 +0200 Message-ID: <87wmyotk74.wl-tiwai@suse.de> From: Takashi Iwai To: Pierre-Louis Bossart Cc: Wesley Cheng , agross@kernel.org, andersson@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, catalin.marinas@arm.com, will@kernel.org, mathias.nyman@intel.com, gregkh@linuxfoundation.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, srinivas.kandagatla@linaro.org, bgoswami@quicinc.com, Thinh.Nguyen@synopsys.com, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, alsa-devel@alsa-project.org, quic_jackp@quicinc.com, oneukum@suse.com, albertccwang@google.com, o-takashi@sakamocchi.jp Subject: Re: [PATCH v4 31/32] sound: usb: card: Allow for rediscovery of connected USB SND devices In-Reply-To: <671a524d-b4c8-78d8-33de-40170a23d189@linux.intel.com> References: <20230725023416.11205-1-quic_wcheng@quicinc.com> <20230725023416.11205-32-quic_wcheng@quicinc.com> <671a524d-b4c8-78d8-33de-40170a23d189@linux.intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Jul 2023 11:15:11 +0200, Pierre-Louis Bossart wrote: > > > > On 7/25/23 04:34, Wesley Cheng wrote: > > In case of notifying SND platform drivers of connection events, some of > > these use cases, such as offloading, require an ASoC USB backend device to > > be initialized before the events can be handled. If the USB backend device > > has not yet been probed, this leads to missing initial USB audio device > > connection events. > > > > Expose an API that traverses the usb_chip array for connected devices, and > > to call the respective connection callback registered to the SND platform > > driver. > > > > Signed-off-by: Wesley Cheng > > --- > > sound/usb/card.c | 19 +++++++++++++++++++ > > sound/usb/card.h | 2 ++ > > 2 files changed, 21 insertions(+) > > > > diff --git a/sound/usb/card.c b/sound/usb/card.c > > index 365f6d978608..27a89aaa0bf3 100644 > > --- a/sound/usb/card.c > > +++ b/sound/usb/card.c > > @@ -170,6 +170,25 @@ struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, > > } > > EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream); > > > > +/* > > + * in case the platform driver was not ready at the time of USB SND > > + * device connect, expose an API to discover all connected USB devices > > + * so it can populate any dependent resources/structures. > > + */ > > +void snd_usb_rediscover_devices(void) > > +{ > > + int i; > > + > > + mutex_lock(®ister_mutex); > > + for (i = 0; i < SNDRV_CARDS; i++) { > > + if (usb_chip[i]) > > + if (platform_ops && platform_ops->connect_cb) > > + platform_ops->connect_cb(usb_chip[i]); > > what happens if the USB device is removed while the platform device adds > a port? That should be protected by the register_mutex. But there can be other races (see below :) > This sounds super-racy to me. It's the same set of problems we're having > between audio and display/DRM, I would be surprised if this function > dealt with all corner cases of insertion/removal, bind/unbind. Yes, we need to be more careful about binding. For example, in the current patch set, I see no way to prevent unloading snd-usb-audio-qmi module, and it allows user to cut off the stuff during operation, which may break things while the kernel is running the code of the unloaded module. You need to have a proper module refcount management for avoiding such a scenario. Most of drivers don't need it because ALSA core part already takes care of it. But in this case, it requires a manual adjustment. Takashi