From patchwork Tue Jun 19 15:24:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 139139 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5344610lji; Tue, 19 Jun 2018 08:25:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIow3Eh2c8tEY6aJp7ICPo82wrY2SRzc9D7iJVmPPXg23OwRcDKf7orbAu9VJSBoXORSyp0 X-Received: by 2002:a1c:d483:: with SMTP id l125-v6mr11342387wmg.98.1529421907216; Tue, 19 Jun 2018 08:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529421907; cv=none; d=google.com; s=arc-20160816; b=kLIx8FHKUhOej7nK2NV+B0NAes01Y9sBfM+FUTRYrpOg2Gge/50P7Gos+hoagL1PFR jEe3KV9HMU51n9Vixp1tlHCaTvPqLT46LsCMogsBSeS/QDFsTxqLR/P2yVyrY1EMjcEx FAU8Me2tANqvWBxMKAaknVaggFs4mUa2n4sVGMvf1I0nCQGFYFX9IwYJUAwEcMgLjkh+ APox1/HPiW48er0v+YfESPoKQV5lHcHpwOkRxLXTxMlGv6T6dCTLTodPrp1iV5UCPsNz c9iTpy/VXdQoxNPHrdpUkf3wzuxSbRkQvKHwVxVCAYWUihmOwWv6i8R2IwbY91ACvBTa n4QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:date:message-id:in-reply-to:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=1ZKh0g7BeoOxCrHkjKPIORi/SXFV95lMde9RC8i25qo=; b=aDShba5BGhTz6PQLQ/cetIxBvLE/3XarUsZDprp5L56VuQfa8VIgs+w7C1y6EdRy1A 46v5Nf1jRwbtjUr5dAJZQQorh+8RDqJfahh0PyxS1t3zFdJJ0UIoYde2/fcpJCDnlB7H 6Fi80zaDTEKSo9tfcNXy4EJB9e6lh+ZJiPcxWWeUOUGFm3ItN6aoV/hjrPyoOvlcajZJ T0g9Qbq+SkoYY+5QWwS74+/HoX/PpguUbml5bV0EuCakYK7ox8fM7ULE7NNretjRDR0i T1ETmPsd7xJlFxWyKeyk+jz/MfyhVPTDCgVwU+On+KSBiBToF3ItlfmcQRZIJGq2ImtU GXjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sirena.org.uk header.s=20170815-heliosphere header.b="XKPTo/NB"; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id r10-v6si2517620wrs.69.2018.06.19.08.25.07; Tue, 19 Jun 2018 08:25:07 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sirena.org.uk header.s=20170815-heliosphere header.b="XKPTo/NB"; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 8504B2676E7; Tue, 19 Jun 2018 17:24:49 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A9B682675D5; Tue, 19 Jun 2018 17:24:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=disabled version=3.4.0 Received: from heliosphere.sirena.org.uk (heliosphere.sirena.org.uk [172.104.155.198]) by alsa0.perex.cz (Postfix) with ESMTP id 5F42E2675FB for ; Tue, 19 Jun 2018 17:24:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=WCVNtwdiPDOsbJ2o0HkootqQnlOxs6RYQAiPBGtIorM=; b=XKPTo/NBJLN9 io3NANAtiSZCQvzwFY3jjl3bjiTYpX0qnmVw4/bVXG7tbM3zBuWp0FseYs20ya2nrl083qqravGLk 4StfmxhwibdTgYBQ0twfHPLYIbUHAVFd+AsYwvVcha1VfHUkL7y0FfkVl2CWgLTU5AwACPG3VHzzs HibbA=; Received: from debutante.sirena.org.uk ([2001:470:1f1d:6b5::3] helo=debutante) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fVIUg-0001L1-BF; Tue, 19 Jun 2018 15:24:30 +0000 Received: from broonie by debutante with local (Exim 4.91) (envelope-from ) id 1fVIUf-0002KV-2l; Tue, 19 Jun 2018 16:24:29 +0100 From: Mark Brown To: Charles Keepax In-Reply-To: <20180619152209.16713-1-ckeepax@opensource.cirrus.com> Message-Id: Date: Tue, 19 Jun 2018 16:24:29 +0100 Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, broonie@kernel.org, lgirdwood@gmail.com, kuninori.morimoto.gx@renesas.com Subject: [alsa-devel] Applied "ASoC: pcm: Tidy up open/hw_params handling" to the asoc tree X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org The patch ASoC: pcm: Tidy up open/hw_params handling has been applied to the asoc tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From 244e293690a6e07cbdfa11af1977488d91931eed Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Tue, 19 Jun 2018 16:22:09 +0100 Subject: [PATCH] ASoC: pcm: Tidy up open/hw_params handling Currently, the core will continue processing open/hw_params component callbacks after one has failed even though it will abort immediately afterwards. This is unnecessary and also has the issue that close/hw_free will be called on the component which failed open/hw_params which could result in issues if the driver doesn't expect this behaviour. Update the core to abort processing open/hw_params when an error is hit and only call close/hw_free for those components that were successfully opened. Signed-off-by: Charles Keepax Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 116 +++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 54 deletions(-) -- 2.17.1 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 5e7ae47a9658..45b52f7b9690 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -448,6 +448,29 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream) hw->rate_max = min_not_zero(hw->rate_max, rate_max); } +static int soc_pcm_components_close(struct snd_pcm_substream *substream, + struct snd_soc_component *last) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_rtdcom_list *rtdcom; + struct snd_soc_component *component; + + for_each_rtdcom(rtd, rtdcom) { + component = rtdcom->component; + + if (component == last) + break; + + if (!component->driver->ops || + !component->driver->ops->close) + continue; + + component->driver->ops->close(substream); + } + + return 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 @@ -462,7 +485,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *codec_dai; const char *codec_dai_name = "multicodec"; - int i, ret = 0, __ret; + int i, ret = 0; pinctrl_pm_select_default_state(cpu_dai->dev); for (i = 0; i < rtd->num_codecs; i++) @@ -486,7 +509,6 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) } } - ret = 0; for_each_rtdcom(rtd, rtdcom) { component = rtdcom->component; @@ -494,16 +516,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) !component->driver->ops->open) continue; - __ret = component->driver->ops->open(substream); - if (__ret < 0) { + ret = component->driver->ops->open(substream); + if (ret < 0) { dev_err(component->dev, "ASoC: can't open component %s: %d\n", - component->name, __ret); - ret = __ret; + component->name, ret); + goto component_err; } } - if (ret < 0) - goto component_err; + component = NULL; for (i = 0; i < rtd->num_codecs; i++) { codec_dai = rtd->codec_dais[i]; @@ -612,15 +633,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) } component_err: - for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; - - if (!component->driver->ops || - !component->driver->ops->close) - continue; - - component->driver->ops->close(substream); - } + soc_pcm_components_close(substream, component); if (cpu_dai->driver->ops->shutdown) cpu_dai->driver->ops->shutdown(substream, cpu_dai); @@ -714,15 +727,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) if (rtd->dai_link->ops->shutdown) rtd->dai_link->ops->shutdown(substream); - for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; - - if (!component->driver->ops || - !component->driver->ops->close) - continue; - - component->driver->ops->close(substream); - } + soc_pcm_components_close(substream, NULL); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (snd_soc_runtime_ignore_pmdown_time(rtd)) { @@ -874,6 +879,29 @@ int soc_dai_hw_params(struct snd_pcm_substream *substream, return 0; } +static int soc_pcm_components_hw_free(struct snd_pcm_substream *substream, + struct snd_soc_component *last) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_rtdcom_list *rtdcom; + struct snd_soc_component *component; + + for_each_rtdcom(rtd, rtdcom) { + component = rtdcom->component; + + if (component == last) + break; + + if (!component->driver->ops || + !component->driver->ops->hw_free) + continue; + + component->driver->ops->hw_free(substream); + } + + return 0; +} + /* * Called by ALSA when the hardware params are set by application. This * function can also be called multiple times and can allocate buffers @@ -886,7 +914,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - int i, ret = 0, __ret; + int i, ret = 0; mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); if (rtd->dai_link->ops->hw_params) { @@ -944,7 +972,6 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, if (ret < 0) goto interface_err; - ret = 0; for_each_rtdcom(rtd, rtdcom) { component = rtdcom->component; @@ -952,16 +979,15 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, !component->driver->ops->hw_params) continue; - __ret = component->driver->ops->hw_params(substream, params); - if (__ret < 0) { + ret = component->driver->ops->hw_params(substream, params); + if (ret < 0) { dev_err(component->dev, "ASoC: %s hw params failed: %d\n", - component->name, __ret); - ret = __ret; + component->name, ret); + goto component_err; } } - if (ret < 0) - goto component_err; + component = NULL; /* store the parameters for each DAIs */ cpu_dai->rate = params_rate(params); @@ -977,15 +1003,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, return ret; component_err: - for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; - - if (!component->driver->ops || - !component->driver->ops->hw_free) - continue; - - component->driver->ops->hw_free(substream); - } + soc_pcm_components_hw_free(substream, component); if (cpu_dai->driver->ops->hw_free) cpu_dai->driver->ops->hw_free(substream, cpu_dai); @@ -1014,8 +1032,6 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, static int soc_pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component; - struct snd_soc_rtdcom_list *rtdcom; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *codec_dai; bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; @@ -1052,15 +1068,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) rtd->dai_link->ops->hw_free(substream); /* free any component resources */ - for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; - - if (!component->driver->ops || - !component->driver->ops->hw_free) - continue; - - component->driver->ops->hw_free(substream); - } + soc_pcm_components_hw_free(substream, NULL); /* now free hw params for the DAIs */ for (i = 0; i < rtd->num_codecs; i++) {