From patchwork Tue Jul 28 06:57:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 11688483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B5366C1 for ; Tue, 28 Jul 2020 07:01:47 +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 E2F28207F5 for ; Tue, 28 Jul 2020 07:01:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="IO1S3MhZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2F28207F5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=renesas.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 6C08F16BA; Tue, 28 Jul 2020 09:00:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6C08F16BA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1595919705; bh=6n9NEBEZ19cluL/1q9o0ixo1ra+HlTmqIqaAoh9gLJE=; h=Date:From:Subject:To:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IO1S3MhZIQwUx4o33t/ZSkvtBh24gQRSF+fNK1r3EoBuEj5DGgriaj4IoF3ng3vdp w9oIeEZmyPZ0J4sX8FzrnijbicpnXPj3itseJAhBWXPYgSkJccJTvWymIZ+Y0g4bwo AKYTjqOs14jNZFh7QiIaedh6lQsi+FC9QtuWToNc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 816ECF8029B; Tue, 28 Jul 2020 08:58:03 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 384E8F802EB; Tue, 28 Jul 2020 08:58:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id 207C9F8029B for ; Tue, 28 Jul 2020 08:57:47 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 207C9F8029B Date: 28 Jul 2020 15:57:45 +0900 X-IronPort-AV: E=Sophos;i="5.75,405,1589209200"; d="scan'208";a="53011657" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 28 Jul 2020 15:57:45 +0900 Received: from mercury.renesas.com (unknown [10.166.252.133]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id B72B04005158; Tue, 28 Jul 2020 15:57:45 +0900 (JST) Message-ID: <87pn8gktzn.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 5/7] ASoC: soc-pcm: add soc_pcm_clean() and call it from soc_pcm_open/close() User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <87wo2oku0m.wl-kuninori.morimoto.gx@renesas.com> References: <87wo2oku0m.wl-kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Cc: Linux-ALSA 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" From: Kuninori Morimoto soc_pcm_open() does rollback when failed (A), but, it is almost same as soc_pcm_close(). static int soc_pcm_open(xxx) { ... if (ret < 0) goto xxx_err; ... return 0; ^ config_err: | ... | rtd_startup_err: (A) ... | component_err: | ... v return ret; } The difference is soc_pcm_close() is for all dai/component/substream, rollback is for succeeded part only. This kind of duplicated code can be a hotbed of bugs, thus, we want to share soc_pcm_close() and rollback. Now, soc_pcm_open/close() are handling 1) snd_soc_dai_startup/shutdown() 2) snd_soc_link_startup/shutdown() 3) snd_soc_component_module_get/put() 4) snd_soc_component_open/close() 5) pm_runtime_put/get() Now, 1) to 5) are handled. This patch adds new soc_pcm_clean() and call it from soc_pcm_open() as rollback, and from soc_pcm_close() as normal close handler. One note here is that it don't need to call snd_soc_runtime_deactivate() when rollback case, because it will be called without snd_soc_runtime_activate(). It also don't need to call snd_soc_dapm_stream_stop() when rollback case. Signed-off-by: Kuninori Morimoto --- sound/soc/soc-pcm.c | 69 ++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 6243e1a0561c..25e368e2b74b 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -651,12 +651,7 @@ static int soc_pcm_components_close(struct snd_pcm_substream *substream, return ret; } -/* - * Called by ALSA when a PCM substream is closed. Private data can be - * freed here. The cpu DAI, codec DAI, machine and components are also - * shutdown. - */ -static int soc_pcm_close(struct snd_pcm_substream *substream) +static int soc_pcm_clean(struct snd_pcm_substream *substream, int rollback) { struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); struct snd_soc_component *component; @@ -665,20 +660,22 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); - snd_soc_runtime_deactivate(rtd, substream->stream); + if (!rollback) + snd_soc_runtime_deactivate(rtd, substream->stream); for_each_rtd_dais(rtd, i, dai) - snd_soc_dai_shutdown(dai, substream, 0); + snd_soc_dai_shutdown(dai, substream, rollback); - snd_soc_link_shutdown(substream, 0); + snd_soc_link_shutdown(substream, rollback); - soc_pcm_components_close(substream, 0); + soc_pcm_components_close(substream, rollback); - snd_soc_dapm_stream_stop(rtd, substream->stream); + if (!rollback) + snd_soc_dapm_stream_stop(rtd, substream->stream); mutex_unlock(&rtd->card->pcm_mutex); - snd_soc_pcm_component_pm_runtime_put(rtd, substream, 0); + snd_soc_pcm_component_pm_runtime_put(rtd, substream, rollback); for_each_rtd_components(rtd, i, component) if (!snd_soc_component_active(component)) @@ -687,6 +684,16 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) return 0; } +/* + * Called by ALSA when a PCM substream is closed. Private data can be + * freed here. The cpu DAI, codec DAI, machine and components are also + * shutdown. + */ +static int soc_pcm_close(struct snd_pcm_substream *substream) +{ + return soc_pcm_clean(substream, 0); +} + /* * Called by ALSA when a PCM substream is opened, the runtime->hw record is * then initialized and any private data can be allocated. This also calls @@ -707,17 +714,17 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ret = snd_soc_pcm_component_pm_runtime_get(rtd, substream); if (ret < 0) - goto pm_err; + goto err; mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); ret = soc_pcm_components_open(substream); if (ret < 0) - goto component_err; + goto err; ret = snd_soc_link_startup(substream); if (ret < 0) - goto rtd_startup_err; + goto err; /* startup the audio subsystem */ for_each_rtd_dais(rtd, i, dai) { @@ -726,7 +733,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) dev_err(dai->dev, "ASoC: can't open DAI %s: %d\n", dai->name, ret); - goto config_err; + goto err; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -755,18 +762,18 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) if (!runtime->hw.rates) { printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n", codec_dai_name, cpu_dai_name); - goto config_err; + goto err; } if (!runtime->hw.formats) { printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n", codec_dai_name, cpu_dai_name); - goto config_err; + goto err; } if (!runtime->hw.channels_min || !runtime->hw.channels_max || runtime->hw.channels_min > runtime->hw.channels_max) { printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n", codec_dai_name, cpu_dai_name); - goto config_err; + goto err; } soc_pcm_apply_msb(substream); @@ -776,7 +783,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) if (snd_soc_dai_active(dai)) { ret = soc_pcm_apply_symmetry(substream, dai); if (ret != 0) - goto config_err; + goto err; } } @@ -787,29 +794,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) runtime->hw.channels_max); pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min, runtime->hw.rate_max); - dynamic: - snd_soc_runtime_activate(rtd, substream->stream); - - mutex_unlock(&rtd->card->pcm_mutex); - return 0; - -config_err: - for_each_rtd_dais(rtd, i, dai) - snd_soc_dai_shutdown(dai, substream, 1); - - snd_soc_link_shutdown(substream, 1); -rtd_startup_err: - soc_pcm_components_close(substream, 1); -component_err: +err: mutex_unlock(&rtd->card->pcm_mutex); -pm_err: - snd_soc_pcm_component_pm_runtime_put(rtd, substream, 1); - for_each_rtd_components(rtd, i, component) - if (!snd_soc_component_active(component)) - pinctrl_pm_select_sleep_state(component->dev); + if (ret < 0) + soc_pcm_clean(substream, 1); return ret; }