From patchwork Fri Dec 25 08:42:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5pyx54G/54G/?= X-Patchwork-Id: 11989937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F449C433DB for ; Fri, 25 Dec 2020 08:44:07 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E590E230FF for ; Fri, 25 Dec 2020 08:44:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E590E230FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=vivo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 644081831; Fri, 25 Dec 2020 09:43:13 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 644081831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1608885843; bh=VJS/J2TP9T00uwaMsyS1+eoIM/9n5h1Or7YKTLjDaBA=; h=To:Subject:From:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=qPwlmDFo6mey42/vslTdSCuQZmQo9PVIepRBh3+OIViENxdocJWsZl0ymwt6vuyID HxDcT9TnGKAjJ7taylYfZNMcB14XtIENX21K99QFrlvV/eAPqORuDd5V0VNRFOKd5J mPxLNXNL2WMB6iP0Lq3TZUu3in59qonDII0dsKzY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C5C9FF80168; Fri, 25 Dec 2020 09:43:12 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A42C2F801D5; Fri, 25 Dec 2020 09:43:10 +0100 (CET) Received: from m176148.mail.qiye.163.com (m176148.mail.qiye.163.com [59.111.176.148]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D63EFF80113 for ; Fri, 25 Dec 2020 09:43:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D63EFF80113 Received: from vivo.com (wm-8.qy.internal [127.0.0.1]) by m176148.mail.qiye.163.com (Hmail) with ESMTP id 63AAF1A4F3A; Fri, 25 Dec 2020 16:42:48 +0800 (CST) Message-ID: To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: =?utf-8?q?ASoC=3A_soc-pcm=3A_disconnect_BEs_if_the_FE_is_not_ready?= X-Priority: 3 X-Mailer: HMail Webmail Server V2.0 Copyright (c) 2016-163.com X-Originating-IP: 58.251.74.232 MIME-Version: 1.0 Received: from zhucancan@vivo.com( [58.251.74.232) ] by ajax-webmail ( [127.0.0.1] ) ; Fri, 25 Dec 2020 16:42:46 +0800 (GMT+08:00) From: =?utf-8?b?5pyx54G/54G/?= Date: Fri, 25 Dec 2020 16:42:46 +0800 (GMT+08:00) X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZHh4fSkgfTB5IHxpOVkpNS0NDQ05MTEpPSElVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS0hKQ1VLWQY+ X-HM-Sender-Digest: e1kMHhlZQQ8JDh5XWRIfHhUPWUFZRzo6FDoJDD8dPxUUHh0CAwECSQwC EhoKFlVKVUpNS0NDQ05MTElJQ0hVMxYaEhdVARMOGBoVGBoVOw0SDRRVGBQWRVlXWRILWUFZTkNV SU5KVUxPVUlISVlXWQgBWUFPT09PNwY+ X-HM-Tid: 0a7699109abb9394kuws63aaf1a4f3a Cc: kernel@vivo.com, trivial@kernel.org, zhucancan@vivo.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" FE is connected to two BEs, BE1 is active, BE2 is deactive. When closing BE1, FE/BE1 is in HW_FREE state, then BE2 is startup by mixer runtime update. For FE is in HW_FREE state, dpcm_run_update_startup() will skip BE2's startup because FE's state is HW_FREE, BE2 stays in FE's be_clients list. During FE's closed, the dpcm_fe_dai_close() will close all related BEs, BE2 will be closed. This will lead to BE2's dpcm[stream].users mismatch. We need disconnet all pending BEs in the corner case. Signed-off-by: zhucancan --- sound/soc/soc-pcm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index dcab9527ba3d..04ad53f0ae4f 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2451,8 +2451,11 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream) /* Only start the BE if the FE is ready */ if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE || - fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE) - return -EINVAL; + fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE) { + dev_err(fe->dev, "ASoC: FE %s is not ready %d\n", + fe->dai_link->name, fe->dpcm[stream].state); + goto disconnect; + } /* startup must always be called for new BEs */ ret = dpcm_be_dai_startup(fe, stream); @@ -2513,12 +2516,18 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream) close: dpcm_be_dai_shutdown(fe, stream); disconnect: - /* disconnect any closed BEs */ + /* disconnect any pending BEs */ spin_lock_irqsave(&fe->card->dpcm_lock, flags); for_each_dpcm_be(fe, stream, dpcm) { struct snd_soc_pcm_runtime *be = dpcm->be; - if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE) - dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; + + /* is this op for this BE ? */ + if (!snd_soc_dpcm_be_can_update(fe, be, stream)) + continue; + + if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE || + be->dpcm[stream].state == SND_SOC_DPCM_STATE_NEW) + dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE; } spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);