From patchwork Tue Feb 18 10:38:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Gerhold X-Patchwork-Id: 193529 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 0E263C34026 for ; Tue, 18 Feb 2020 10:40:00 +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 8DB0D2173E for ; Tue, 18 Feb 2020 10:39:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="mpY3apR9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gerhold.net header.i=@gerhold.net header.b="dx0+qo94" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DB0D2173E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gerhold.net 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 E94981672; Tue, 18 Feb 2020 11:39:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E94981672 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1582022398; bh=qZb6wGF9fQlv3kx73brqYG8mVyhaG+MTC5NkyLN+xBs=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=mpY3apR9tILQ1fmUm3hfS1iOgr8M3gcNUS1aU7/pPT35nxJ8oIfLUh8ywho7S/w45 lYwVSbAU7XzdGSBvbgTjPUCa7C9Qk58a2fpO0Nd1Z3Xt9OjYhytOG0/k0LDrSQ0qZX w8p2SxyXbC+jXxcniIeBZbkFyPDo1MZaWFMtSaCs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 45EC5F80145; Tue, 18 Feb 2020 11:39:07 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 85F86F80148; Tue, 18 Feb 2020 11:39:05 +0100 (CET) Received: from mo6-p01-ob.smtp.rzone.de (mo6-p01-ob.smtp.rzone.de [IPv6:2a01:238:20a:202:5301::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7676CF80135 for ; Tue, 18 Feb 2020 11:38:58 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7676CF80135 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gerhold.net header.i=@gerhold.net header.b="dx0+qo94" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1582022337; s=strato-dkim-0002; d=gerhold.net; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=EeehLX+3+hs8grdPum9plCG+8WHPa0wPcl2xZHiYQGk=; b=dx0+qo94dxf8VyjiHQBE/+vMpKn6dZhHu46YBvrpuo6YeZjHOHSR+xk+07zDhVcYsk dSktXbeRZeTQs8bSe6gPi42omq+vmCCLWGWSrwSb/jse2gnipHSsNYiipDMtii9dR/dW be0jpcALlxVpVqJctWa1X7sBtoi1qeD+XsniltsJyNkPdHoOXyYPKwFtbqXWOFdTytmW UuswkN3XqJzGk3H8xlK0wRj/xCoSEca73XzTajZyYnTvyfX3WsscsGZxw1aOH473y8yM 9URiPqm0PcpkrLpl2eauxiWLkEW50nqegzgEss7NFMXDj1W+4p7ECx83GSRcjEoX/Ier 9DuQ== X-RZG-AUTH: ":P3gBZUipdd93FF5ZZvYFPugejmSTVR2nRPhVORvLd4SsytBXS7IYBkLahKxP4W6NDcj7" X-RZG-CLASS-ID: mo00 Received: from localhost.localdomain by smtp.strato.de (RZmta 46.1.12 DYNA|AUTH) with ESMTPSA id a01fe9w1IAcri1h (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 18 Feb 2020 11:38:53 +0100 (CET) From: Stephan Gerhold To: Mark Brown Subject: [PATCH] ASoC: soc-pcm: fix regression in soc_new_pcm() Date: Tue, 18 Feb 2020 11:38:24 +0100 Message-Id: <20200218103824.26708-1-stephan@gerhold.net> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Stephan Gerhold , Sameer Pujar , Takashi Iwai , Liam Girdwood , Jerome Brunet 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" Commit af4bac11531f ("ASoC: soc-pcm: crash in snd_soc_dapm_new_dai") swapped the SNDRV_PCM_STREAM_* parameter in the snd_soc_dai_stream_valid(cpu_dai, ...) checks. But that works only for codec2codec links. For normal links it breaks registration of playback/capture-only PCM devices. E.g. on qcom/apq8016_sbc there is usually one playback-only and one capture-only PCM device, but they disappeared after the commit. The codec2codec case was added in commit a342031cdd08 ("ASoC: create pcm for codec2codec links as well") as an extra check (e.g. `playback = playback && cpu_playback->channels_min`). We should be able to simplify the code by checking directly for the correct stream type in the loop. This also fixes the regression because we check for PLAYBACK for both codec and cpu dai again when codec2codec is not used. Cc: Sameer Pujar Cc: Jerome Brunet Fixes: af4bac11531f ("ASoC: soc-pcm: crash in snd_soc_dapm_new_dai") Signed-off-by: Stephan Gerhold --- Original report of the regression: https://lore.kernel.org/alsa-devel/20200217144120.GA243254@gerhold.net/ I'm still quite confused about the crash that was fixed by the commit that introduced the regression... If anything, the original code added in commit a342031cdd08 ("ASoC: create pcm for codec2codec links as well") should have been too "restrictive" since it checked for both PLAYBACK and CAPTURE for the cpu dai in the codec2codec case... Audio works fine gain on apq8016_sbc with this patch, but I don't have any device with codec2codec to test this. --- sound/soc/soc-pcm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index ff1b7c7078e5..cfa24d214a9c 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2888,22 +2888,19 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) capture = rtd->dai_link->dpcm_capture; } else { /* Adapt stream for codec2codec links */ - struct snd_soc_pcm_stream *cpu_capture = rtd->dai_link->params ? - &cpu_dai->driver->playback : &cpu_dai->driver->capture; - struct snd_soc_pcm_stream *cpu_playback = rtd->dai_link->params ? - &cpu_dai->driver->capture : &cpu_dai->driver->playback; + int cpu_capture = rtd->dai_link->params ? + SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE; + int cpu_playback = rtd->dai_link->params ? + SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; for_each_rtd_codec_dai(rtd, i, codec_dai) { if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) && - snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE)) + snd_soc_dai_stream_valid(cpu_dai, cpu_playback)) playback = 1; if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) && - snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK)) + snd_soc_dai_stream_valid(cpu_dai, cpu_capture)) capture = 1; } - - capture = capture && cpu_capture->channels_min; - playback = playback && cpu_playback->channels_min; } if (rtd->dai_link->playback_only) {