From patchwork Wed Sep 20 15:36:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chancel Liu X-Patchwork-Id: 13393024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A5053C04A97 for ; Wed, 20 Sep 2023 15:38:27 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id DCC14A4A; Wed, 20 Sep 2023 17:37:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DCC14A4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1695224304; bh=gIw5cZPg0jXoHBQEgKh8X6VOza3msHrcfiaW8O6LT4I=; h=From:To:Cc:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=lSIKrjX61x/RsX9ovpglLHji7T5lW7nAYCAe/qW/dpHZ1oCkRQEsdoOcoiO4ugrPN ZO4dlB8Vn1IgFdNvliD/AVzJ+Zn5PkKEEypTf+o+j2yAM37qFsqBkXEMRO0TIQ0zaZ +toIubJGYgp9SMex7tFIbdMaWlthnxpg9o4OZ8aE= Received: by alsa1.perex.cz (Postfix, from userid 50401) id D829DF8047D; Wed, 20 Sep 2023 17:36:56 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 05F19F800AA; Wed, 20 Sep 2023 17:36:56 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A276CF8047D; Wed, 20 Sep 2023 17:36:50 +0200 (CEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2061a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1a::61a]) (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 0FA24F800F4 for ; Wed, 20 Sep 2023 17:36:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0FA24F800F4 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=qTCXZko4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nYoRJ0BfeMy28zK770K1fy6O3Xre4xKYVEK5S/rZxbb/d8ohK08lHxvwkzVkxtuih14huB4DTNJXxm8W7Z/L74ZiZelZs8ou68bg+wZf+1i8yjBkE0evhhkm40stFCtfyAlrzmR6dJ/FtfItDjI51esRyN2Cf0qUzy1+hH2h1mLlZz2crqYaPq744eHW8xqWVZ7LtAGAa4jQeCgF1yAHggmzvrft1Lez+njwZ4pdTdnd8tLLjd79zdE+kkoFYCN27dnpRPlDgSPDIc3RBNQ132QZyPsbXa/lnB9YIBOETXYgw+VeqeB3tlFIP/FlPpOb8JdQfD4tIihQ9IiBwOYyGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pUPoKTtJAGz2bWN3S7LB+iQwI/DdO5FNtE1ERK6mLwg=; b=ivEtjpBnIo8rXYvYxwuEanTZQqORjMb72NzBo6cBv+0M3zMwa3Zvbn6C2SCMkBf/yedaveDkALnVp4uBl0cpPBtVHrG+aaEn1jebW+c9NKLdE8tMQeHgnXuRWmtkFxd9Gk4PGpMvrOrXajNmMvOjD70TiG1axVCaee1S1JUq2jyU7wGuhAt0Xv3RVoOyZUKzgPL9Ke49NOcVE8ipfjA99ukdLwACtL61QY8RBnrUkN0moMq2GnnymOipi6jVLD30WnTxENVAgTIH03yoovSD2sI61ct7xWLDo4640302scGK5hA9OPIywRaxuao9iHVcUmFn+1GEf98MZdoh0UZ68w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pUPoKTtJAGz2bWN3S7LB+iQwI/DdO5FNtE1ERK6mLwg=; b=qTCXZko4RQyy+myTEfjdSYZNH6zuV4JcVgre0lnrwps+CtLfbL87qG7kbJOd9X+u/jKYj+wq4w2iZuGF3DxnJWUVD4KgRNy+g8uztPxHmzGWJi0XtnHpnxa45Mv4rMhifoBi8vY666ryzVW1rzkxvwsIrb50DQ6Azk2gj/NciTo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB9PR04MB9498.eurprd04.prod.outlook.com (2603:10a6:10:360::21) by DUZPR04MB9748.eurprd04.prod.outlook.com (2603:10a6:10:4e0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Wed, 20 Sep 2023 15:36:39 +0000 Received: from DB9PR04MB9498.eurprd04.prod.outlook.com ([fe80::51f9:b8d2:7ddd:c74f]) by DB9PR04MB9498.eurprd04.prod.outlook.com ([fe80::51f9:b8d2:7ddd:c74f%6]) with mapi id 15.20.6792.026; Wed, 20 Sep 2023 15:36:39 +0000 From: Chancel Liu To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: Chancel Liu Subject: [PATCH v2 0/1] ASoC: soc-pcm.c: Make sure DAI parameters cleared if the DAI becomes inactive Date: Wed, 20 Sep 2023 23:36:20 +0800 Message-Id: <20230920153621.711373-1-chancel.liu@nxp.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: SI1PR02CA0037.apcprd02.prod.outlook.com (2603:1096:4:1f6::13) To DB9PR04MB9498.eurprd04.prod.outlook.com (2603:10a6:10:360::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR04MB9498:EE_|DUZPR04MB9748:EE_ X-MS-Office365-Filtering-Correlation-Id: ca98d04c-5b2a-4952-0030-08dbb9ef6204 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V2RnLZisZ6/StIBSTRKQp/SMLfqaXYLiAW3C2/9lLlzJZjPXS3naxgvkQ13cc6BcRztNgLX8dO1/9HeSR3ShSgL1gxV3ELl6mRCkNzfGKfis6BGomuQbOmh7NDxyaaZgs/AycH7tZirVfZbawc9nHaP7mS/xwlll0SiDhyNF/tPqgN05pLp5XsHnPd9q6cB7x4dP5eCM1luB26+nyDOHQG4M6z0jXCCfLFcG56//EJZsWTgAAzSOL9WsGe/8a0VLKdMhjKtsRx8ZO1mPbUpR6KL8nkDeHmCbXlaKegXRbsubDspdHPP7TzPnlcEFMS7aKH964/zkBPDuqMFBmJOAEN/OZHw36yRS4xWZ09k8kb0h0DnjF/NKvKYp+OCdWqdjSrhM4i+3hMSWKUO6oP7q6uWTAJLnEfLmmkRpZEv4q+Pnjrrw6JXJMyj5BfYy4pDTf+lp8bQ9EUop8p88NydqGJNtplT7NmikSUhkZ389eZnu0Y3Kb0U9tZvQyrgK6tluJmgvC/eF8EV8x1qZ34kMq+ULYc6cNIEq/yAHXpgA4oqGXBc+RFz3ZJO8MvmDdx8KUcInANar7fIXIaUtPuueUQT7CSyOFCl/dB6Fyq1G05w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR04MB9498.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(396003)(366004)(346002)(39860400002)(376002)(186009)(451199024)(1800799009)(966005)(6666004)(6512007)(52116002)(6506007)(6486002)(36756003)(86362001)(66476007)(66556008)(41300700001)(38100700002)(66946007)(316002)(478600001)(38350700002)(1076003)(8936002)(4326008)(8676002)(26005)(44832011)(5660300002)(83380400001)(2616005)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 10kqLl+vnwnZPC/NVGUeJzAnBbZR2jokMNFm9U8BcvsmvUXe5vC+uRp+w5pkN05BRmpJJ9VyxOF+Zr0OLGjPgBAhgnEEZdcHombMiLRs2u0CODG0mQ1Ryda2mKwC1qW6EWHdTGNIx+nVBiOKpJUNCBoz2JCFtDoeaWDz15o1cAm4EL+KyiiIX9B0cjZrfTTfLmVqNgLr8m6uY3Mvk/kONknRfCtm705PoQCw3fIuvIhik0lU93efHcBdbcTUFnAV5/rZKHCTcAG85+ShnCavSWgt0vEHy2XZC9UxYhg981YW4k7aXWukvE59AVG4VtszjXZnbMgHZ3Av8tWCQHnvFaWnUo+kKwbfNF5oIGVHiVN07Fqpl/kuHEQwmYCO42upXiRHAll1atwoEqDLy8SL2axPkBYPzHVQx1mv80bEoIbkfFWPIQL25xNcZJJ009qZ3dOsVgq9ntqmsZF015lJhX4D8B3HQF0GzjHlZgHUntkLxXeUFFLFqH/bpIh0IpamN4nL0lQYJkZQqFw2WvzysMmj6sMDAPZ84MsGa/Dzm3GqB8bmNJyZKgR4jJe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: ca98d04c-5b2a-4952-0030-08dbb9ef6204 X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB9498.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 15:36:39.8248 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ahxiEhQAoVwPNCsLw9bjbz1V2ePvVVDnKs0MKPTzehIn1f5yAHEJjRbvnpW63apPw9nBYCpajcWt+LBXF9clNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9748 Message-ID-Hash: RQTEW2ZHSZRI7OFUIR7RFFGEBK2N65IL X-Message-ID-Hash: RQTEW2ZHSZRI7OFUIR7RFFGEBK2N65IL X-MailFrom: chancel.liu@nxp.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: It's reasonable that DAI parameters should be cleared if current DAI becomes inactive. Only check DAI active status in soc_pcm_hw_free() is not enough since there's the risk that DAI parameters never be cleared if there're more than one stream [see A]. Only check DAI active status in soc_pcm_close() is also not enough since it will cause the cleanup just happening in soc_pcm_close() [see B]. [A] For example, we have stream1 and stream2 for DAI about to stop. stream2 executes soc_pcm_hw_free() before stream1 executes soc_pcm_close(). At the moment, stream2 should clear current DAI parameters because stream1 passed the cleanup stage in soc_pcm_hw_free() and stream2 in fact is the only active stream which has a chance to do clean up. Since DAI active status is not yet updated by stream1 in soc_pcm_close(), stream2 doesn't know itself should clear DAI parameters. In result both stream1 and stream2 don't clear the parameters. [B] Suppose a case: aplay -Dhw:0 44100.wav 48000.wav In this case, we call soc_pcm_open()->soc_pcm_hw_params()->soc_pcm_hw_free() ->soc_pcm_hw_params()->soc_pcm_hw_free()->soc_pcm_close() in order. The DAI parameters would be remained in the system even if the playback of 44100.wav is finished. In conclusion, it's better to check DAI active status in both soc_pcm_hw_free() and soc_pcm_close() which makes sure DAI parameters cleared if the DAI becomes inactive. changes in v2: - Patch v1 link: https://lore.kernel.org/all/20230112065834.580192-1-chancel.liu@nxp.com/ Patch v1 tries to introduce a usage count called hw_params_count to fix issue on DAI parameters cleanup. However it's not a good fix because not considering hw_params() and hw_free() are not symmetrical and hw_params() might be called multilpe times by user. - Both check DAI active status in soc_pcm_hw_free() and soc_pcm_close() which makes sure DAI parameters cleared if the DAI becomes inactive. Chancel Liu (1): ASoC: soc-pcm.c: Make sure DAI parameters cleared if the DAI becomes inactive sound/soc/soc-pcm.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) --- 2.25.1