From patchwork Fri Mar 24 01:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666568 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 368C6C6FD1C for ; Fri, 24 Mar 2023 01:30:39 +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 1FEF1E95; Fri, 24 Mar 2023 02:29:47 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1FEF1E95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621437; bh=gcrf/FbQBSeQnVxYB0FjcaGgfLmGLOOfeKwKl/xbKbI=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=XgL7GoV2Qk3HoKPdtBL3P7Tp//pr3JEcTJJwPViPsTHbw/YuWZvcRKNTXFZEXOmFY oyb+ll8DrdNoxEsn4274/uA64D0s2qmsGEuQdDmvBzfK4xNvd+fkj0bPWwOcTaRAh/ bQHrEJAAlGzFpPdwQOBmqZEn/tm9uFBb/Z4dqjUA= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B44B0F80534; Fri, 24 Mar 2023 02:29:23 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 16086F8052E; Fri, 24 Mar 2023 02:29:13 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 63B63F8027B for ; Fri, 24 Mar 2023 02:28:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 63B63F8027B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jBmzR015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621340; x=1711157340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gcrf/FbQBSeQnVxYB0FjcaGgfLmGLOOfeKwKl/xbKbI=; b=jBmzR015SL2jOez7xgVOO2PeFoV1/t56WBV3L/89tXbFcxcijmyYktsR rMwM8GllhIFeOkAYM9dg9gNnpOqCCDiRZ9tlrIe3uISVdwEVhDsQd26LB qexWbmhwNJdNiiHq3CWTa/ImvAOsB323PjJ8IXKLpEQpxJUG8Np5vbxv2 7IIfqwZXuECFDybc3+W0qpOMgQApeeRISZ5KgVodZ+5edmkc3EnwAqqjg o0rlhmrfkxCgF+/fntvsQDTxrF/HQPc82QNWpRZFRidkXdwvUKlgaN0WB r+rscWk1FwdnHvrJg+oaqBqK67sbYMnhSXTxGI70gR659TUfuOhql1FJp w==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584848" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584848" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659872992" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659872992" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:53 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 01/13] ASoC: codecs: cs42l42-sdw: clear stream Date: Fri, 24 Mar 2023 09:43:56 +0800 Message-Id: <20230324014408.1677505-2-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: DFLHVFLMDZJYA3WUIHHNNARGYJTOVQ7W X-Message-ID-Hash: DFLHVFLMDZJYA3WUIHHNNARGYJTOVQ7W X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart The API requires the stream info to be cleared when the argument is NULL. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/cs42l42-sdw.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sound/soc/codecs/cs42l42-sdw.c b/sound/soc/codecs/cs42l42-sdw.c index 7b539ee55499..eeab07c850f9 100644 --- a/sound/soc/codecs/cs42l42-sdw.c +++ b/sound/soc/codecs/cs42l42-sdw.c @@ -152,9 +152,6 @@ static int cs42l42_sdw_port_prep(struct sdw_slave *slave, static int cs42l42_sdw_dai_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - if (!sdw_stream) - return 0; - snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; From patchwork Fri Mar 24 01:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666567 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 CBAD5C74A5B for ; Fri, 24 Mar 2023 01:31:14 +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 3894FED9; Fri, 24 Mar 2023 02:30:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3894FED9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621472; bh=wjw34KdtCxm3W44AGkSEc9zBd1GmuZfgTUhmIbn2tWI=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=OhCxEc6ZMEg8pU9pPIRk5jPgWvYLN2z5ukOk7GRwGPo1dRgoFo1vydX2qmhmmfJkf WcT36mWjdDoyPqZMtQVVJfaTyPgxeQW4eIE/xyZpu1H0tOwEz/tceYoQKz/zBaAkR+ 4TsCqLKcDXF/M+NxdkYaSXdY6niDHTmQeyIcmH8g= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 18B0FF80549; Fri, 24 Mar 2023 02:29:26 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id EA9DBF80534; Fri, 24 Mar 2023 02:29:20 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 9F510F8024E for ; Fri, 24 Mar 2023 02:29:00 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9F510F8024E Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SnVtrW7p DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621342; x=1711157342; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wjw34KdtCxm3W44AGkSEc9zBd1GmuZfgTUhmIbn2tWI=; b=SnVtrW7poJ84QjYKa9nB/8PeVL1fhRqWF8UoiBK3ktLeSHVX/FvzpAvw 6u4tFBt0Q3yVTLlI69RIzSHc+h+2gYrHgUe1EmUg6lYkEsbatCdgPKVa7 S4kARcDjWkAWuv58ZU/LC4vuy01fpI1oCEpWTiasdGCy1IKZiHitx64EQ bQShs6d7dEJVN2rRvR6QaHdYU4BUQPTn4XXEbVAWnZ4PE7sH52TXR9CPX UJtX4WQeE7PkQ59zDhmphEGN9g7hmCrItSJXQrbnOE8TIupyJUOyZNcLE PHNN0z3uIwNIRBb72PJzaD+hkIFMcAenCb3bhcnoCSA+rAuC3TRQ9aA21 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584852" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584852" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659872998" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659872998" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:55 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 02/13] ASoC: codecs: sdw-mockup: simplify set_stream Date: Fri, 24 Mar 2023 09:43:57 +0800 Message-Id: <20230324014408.1677505-3-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: QBYOYBW7LHA457N2AV447Y2S24T6RS23 X-Message-ID-Hash: QBYOYBW7LHA457N2AV447Y2S24T6RS23 X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/sdw-mockup.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/sound/soc/codecs/sdw-mockup.c b/sound/soc/codecs/sdw-mockup.c index 62b02d764f09..5498ff027c58 100644 --- a/sound/soc/codecs/sdw-mockup.c +++ b/sound/soc/codecs/sdw-mockup.c @@ -23,10 +23,6 @@ struct sdw_mockup_priv { struct sdw_slave *slave; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - static int sdw_mockup_component_probe(struct snd_soc_component *component) { return 0; @@ -45,19 +41,7 @@ static const struct snd_soc_component_driver snd_soc_sdw_mockup_component = { static int sdw_mockup_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -65,11 +49,7 @@ static int sdw_mockup_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void sdw_mockup_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int sdw_mockup_pcm_hw_params(struct snd_pcm_substream *substream, @@ -80,11 +60,10 @@ static int sdw_mockup_pcm_hw_params(struct snd_pcm_substream *substream, struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); int ret; - stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!sdw_mockup->slave) @@ -99,7 +78,7 @@ static int sdw_mockup_pcm_hw_params(struct snd_pcm_substream *substream, port_config.num = 8; ret = sdw_stream_add_slave(sdw_mockup->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (ret) dev_err(dai->dev, "Unable to configure port\n"); @@ -111,13 +90,12 @@ static int sdw_mockup_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = - snd_soc_dai_get_dma_data(dai, substream); + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!sdw_mockup->slave) return -EINVAL; - sdw_stream_remove_slave(sdw_mockup->slave, stream->sdw_stream); + sdw_stream_remove_slave(sdw_mockup->slave, sdw_stream); return 0; } From patchwork Fri Mar 24 01:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666565 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 691E2C74A5B for ; Fri, 24 Mar 2023 01:32:20 +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 6A8E4EEC; Fri, 24 Mar 2023 02:31:28 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6A8E4EEC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621538; bh=rXzyOVa6hGhSz8CheEMCIVTNqh5vslmX0LZ52J+Uwag=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=q8mAtHQE9qwwgM+cSDXSSNkxsldH8PlJO/jJScRxNLY63mL1CEG8YA3Om46aPnJDi KZvM7SDRxWzRxrveHeCD7DHYVX0xohLm/B8atsa6gltx67hvcdJcRjhtrNdIWpnbZv 5pvQV79ERLRdckW21wicyemIEB5SsUDlZinVBEpo= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 6BEB5F8057B; Fri, 24 Mar 2023 02:29:47 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7F863F80564; Fri, 24 Mar 2023 02:29:41 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 91F01F8051B for ; Fri, 24 Mar 2023 02:29:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 91F01F8051B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=U5oS4hlD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621346; x=1711157346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rXzyOVa6hGhSz8CheEMCIVTNqh5vslmX0LZ52J+Uwag=; b=U5oS4hlD8s3Y6zJC/g/fhqC6GrQgT8KdZcsrLuTlXq+kF19vXTwc3uEc NL3+1LeqtKU2vEzBAB3A1vFCPrPO53UCjMdyI/1wueL2M/6laLdZ3hpzI 7A7ge3gPStsvmWtkgPkO3dojaFqrqMzn+2aTAPK9y1jsLQM+Y54vuR2uy +rXfFxahyL03Iu5zbGYZiaMEAJA4M4FM8TdZU6LrPuzQ1pfR1owEFcw/q 5UWe6nKhUyyElz6TqrtmQjjvhHqKMJBNlJ2jwFMv+cIoncobeguxbyhDY XCPlMfSNRJZn3YWIQ0bziSPnemirwxRIS4uC17cNlhtTB3BP3o521idbG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584857" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584857" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873004" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873004" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:57 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 03/13] ASoC: codecs: max98373-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:43:58 +0800 Message-Id: <20230324014408.1677505-4-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: FVTQ75JMKEJ7PKWSZDSGDANHRTJFN7X2 X-Message-ID-Hash: FVTQ75JMKEJ7PKWSZDSGDANHRTJFN7X2 X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/max98373-sdw.c | 34 +++++++-------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/max98373-sdw.c b/sound/soc/codecs/max98373-sdw.c index c9a2d4dabd3c..df92242af960 100644 --- a/sound/soc/codecs/max98373-sdw.c +++ b/sound/soc/codecs/max98373-sdw.c @@ -20,10 +20,6 @@ #include "max98373.h" #include "max98373-sdw.h" -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - static const u32 max98373_sdw_cache_reg[] = { MAX98373_R2054_MEAS_ADC_PVDD_CH_READBACK, MAX98373_R2055_MEAS_ADC_THERM_CH_READBACK, @@ -536,12 +532,12 @@ static int max98373_sdw_dai_hw_params(struct snd_pcm_substream *substream, snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int ret, chan_sz, sampling_rate; - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!max98373->slave) @@ -565,7 +561,7 @@ static int max98373_sdw_dai_hw_params(struct snd_pcm_substream *substream, } ret = sdw_stream_add_slave(max98373->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (ret) { dev_err(dai->dev, "Unable to configure port\n"); return ret; @@ -664,32 +660,20 @@ static int max98373_pcm_hw_free(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct max98373_priv *max98373 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!max98373->slave) return -EINVAL; - sdw_stream_remove_slave(max98373->slave, stream->sdw_stream); + sdw_stream_remove_slave(max98373->slave, sdw_stream); return 0; } static int max98373_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -697,11 +681,7 @@ static int max98373_set_sdw_stream(struct snd_soc_dai *dai, static void max98373_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int max98373_sdw_set_tdm_slot(struct snd_soc_dai *dai, From patchwork Fri Mar 24 01:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666943 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 2659EC6FD1C for ; Fri, 24 Mar 2023 01:31:29 +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 CA109EDD; Fri, 24 Mar 2023 02:30:37 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CA109EDD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621487; bh=T1CfiQVovcafr4kXzGGvPGrORmo91gBFgA3c4AfYDro=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=qKGP9S/Qdrlz8PTbIpBK1OybmyeXQQ7xP5z06RkBsa638iok6GvseJOkafjbl+ZfO TCUXq+hv8S38zvnLwlfC2Zphgk6G7l8tfwLqetLzCKIg4K9DKFLGvIOn3PZGgMoRpV hc0+IgJEujWje89vsOJl96J/XCazu/WN7G9OC/jQ= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 919F5F80558; Fri, 24 Mar 2023 02:29:30 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 64B7CF80558; Fri, 24 Mar 2023 02:29:26 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 94D26F802E8 for ; Fri, 24 Mar 2023 02:29:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 94D26F802E8 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=W52+R14s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621342; x=1711157342; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T1CfiQVovcafr4kXzGGvPGrORmo91gBFgA3c4AfYDro=; b=W52+R14scKoFXRYtisd2Ly2z+XU5YS59M37R811yuglRGEzV7Jyndfcw 3H8rN3EZCM/9eh3aP3Vp7dr+roYH4QthQu9TxpIXzA21VSfm/1xi61HMY aXVsUZskZDoXEkxxlr/3yll0Ou3/cJCRXAgiWyCQFDUE0QsWqqrcdYA4Q aXxhrbPMWIZyDOOIGrxoh/vXH9ffKRBKSmx2DSUbBI1q5AjbEQOFrAgjA ALO1wXqJu3g7rPkjczKj20z+7jxVJ+jpf6HvPPNs2SD45ScnHXNonLUEp M7Jp9ILSkfsmLl5JbRZBJkh9Lsmkt1oaAGU69L+gBp+DA0oXJT3eVPs8/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584865" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584865" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873014" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873014" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:28:59 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 04/13] ASoC: codecs: rt1308-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:43:59 +0800 Message-Id: <20230324014408.1677505-5-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: CT6P5HXYQMPF2P4ZMMDIGZZINMSGZIQK X-Message-ID-Hash: CT6P5HXYQMPF2P4ZMMDIGZZINMSGZIQK X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt1308-sdw.c | 30 +++++++----------------------- sound/soc/codecs/rt1308-sdw.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c index 45544b530d3d..1797af824f60 100644 --- a/sound/soc/codecs/rt1308-sdw.c +++ b/sound/soc/codecs/rt1308-sdw.c @@ -496,19 +496,7 @@ static const struct snd_soc_dapm_route rt1308_dapm_routes[] = { static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -516,11 +504,7 @@ static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt1308_sdw_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt1308_sdw_set_tdm_slot(struct snd_soc_dai *dai, @@ -553,13 +537,13 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream, snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt1308->sdw_slave) @@ -580,7 +564,7 @@ static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream, } retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -595,13 +579,13 @@ static int rt1308_sdw_pcm_hw_free(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct rt1308_sdw_priv *rt1308 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt1308->sdw_slave) return -EINVAL; - sdw_stream_remove_slave(rt1308->sdw_slave, stream->sdw_stream); + sdw_stream_remove_slave(rt1308->sdw_slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt1308-sdw.h b/sound/soc/codecs/rt1308-sdw.h index 1eaaef9f351b..04ff18fa18e2 100644 --- a/sound/soc/codecs/rt1308-sdw.h +++ b/sound/soc/codecs/rt1308-sdw.h @@ -170,8 +170,4 @@ struct rt1308_sdw_priv { unsigned int bq_params_cnt; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - #endif /* __RT1308_SDW_H__ */ From patchwork Fri Mar 24 01:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666566 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 239A4C74A5B for ; Fri, 24 Mar 2023 01:31:53 +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 14C4EE92; Fri, 24 Mar 2023 02:31:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 14C4EE92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621511; bh=lRbNssYAu75q3WNYc+et1KrEUH9fnr6g1KllQLa/v9Q=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=lXd8PaX7fEQBwDwwCCaErSOVTxu1WaD/t76FVvZ9vP05/Y4/JCPpsjh31Hx1go0uv IB64UVSHrGInUyR/QiSlR+UAAU0KvOvC4dn9jtkgrWIq1kVTZMaIxt1paLmPC7+Lk+ AbH+ncWOSqfTRbnajarp/tG31jfqEK5sUNjsRSZc= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id F1E17F8055C; Fri, 24 Mar 2023 02:29:35 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 25B1FF8055C; Fri, 24 Mar 2023 02:29:31 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 37996F80482 for ; Fri, 24 Mar 2023 02:29:05 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 37996F80482 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Bsn7sqWk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621346; x=1711157346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lRbNssYAu75q3WNYc+et1KrEUH9fnr6g1KllQLa/v9Q=; b=Bsn7sqWklYn/rhVmqfT8I1kOTkfyyiNTk2k4Zr2uCzbjjGwgBOI6+Dns bhsbbmmASanyycXkwiGbOzwiJZ84WTP9aeXDLjRhtVuE+AyUbI1TnoRA1 OqPQQDzZh6qvA1tB6wYNztVXf9co9dqzEuHZ6SKzLmZwE/JXXZ4pvQfrF ncVw+xhMolU8uJB+v+td+CzysfDoOlDsucpt+y5AeTjpSKkDlNlQ1Rfi/ N4z3pyWT4EZUWJRRUZN7wUlY9bYp64yBUHhagnGnWFZGDq14F/Lp2+i+Y UvM56vYiF1iPoOXFJTzOd3e1IA5GmCZKOXEg6pvdZbeRC/jvF25pZ573v A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584878" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584878" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873026" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873026" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:01 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 05/13] ASoC: codecs: rt1316-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:44:00 +0800 Message-Id: <20230324014408.1677505-6-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: 6CLUHUXLFPYMGPDOEUE7YD4X4W7YCEYG X-Message-ID-Hash: 6CLUHUXLFPYMGPDOEUE7YD4X4W7YCEYG X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt1316-sdw.c | 30 +++++++----------------------- sound/soc/codecs/rt1316-sdw.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt1316-sdw.c b/sound/soc/codecs/rt1316-sdw.c index b45121ee7533..2ee5e763e345 100644 --- a/sound/soc/codecs/rt1316-sdw.c +++ b/sound/soc/codecs/rt1316-sdw.c @@ -494,19 +494,7 @@ static const struct snd_soc_dapm_route rt1316_dapm_routes[] = { static int rt1316_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -514,11 +502,7 @@ static int rt1316_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt1316_sdw_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt1316_sdw_hw_params(struct snd_pcm_substream *substream, @@ -529,13 +513,13 @@ static int rt1316_sdw_hw_params(struct snd_pcm_substream *substream, snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt1316->sdw_slave) @@ -551,7 +535,7 @@ static int rt1316_sdw_hw_params(struct snd_pcm_substream *substream, port_config.num = 2; retval = sdw_stream_add_slave(rt1316->sdw_slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -566,13 +550,13 @@ static int rt1316_sdw_pcm_hw_free(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct rt1316_sdw_priv *rt1316 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt1316->sdw_slave) return -EINVAL; - sdw_stream_remove_slave(rt1316->sdw_slave, stream->sdw_stream); + sdw_stream_remove_slave(rt1316->sdw_slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt1316-sdw.h b/sound/soc/codecs/rt1316-sdw.h index 57dbd49993b0..e37121655bc1 100644 --- a/sound/soc/codecs/rt1316-sdw.h +++ b/sound/soc/codecs/rt1316-sdw.h @@ -50,8 +50,4 @@ struct rt1316_sdw_priv { unsigned int bq_params_cnt; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - #endif /* __RT1316_SDW_H__ */ From patchwork Fri Mar 24 01:44:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666942 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 3746CC74A5B for ; Fri, 24 Mar 2023 01:32:00 +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 E92B7EE7; Fri, 24 Mar 2023 02:31:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E92B7EE7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621518; bh=yWKTdjTalqvw+4k9e+5wDSSpz/nWuKDr1M8WkzT7cNs=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=dQ7MrUtoa9ekCKIN/FxX9e1UEEYNKToMIIB+ndnmMGcCq7EjMezPJnWtW/5c6x51D 6oMEgttQTigbDlys6NU91gyvAWFpiN7V5iZsjXF6oLyxcPxEuKiQYvTbBOUesFhEuL 77R1C1HxQtvReJXYe8Kw9V9g6sHAZGuG5Ts/yfBg= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B146BF80564; Fri, 24 Mar 2023 02:29:42 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 10D13F80482; Fri, 24 Mar 2023 02:29:36 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 8FC23F804FE for ; Fri, 24 Mar 2023 02:29:05 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8FC23F804FE Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=MEWwZsoR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621346; x=1711157346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yWKTdjTalqvw+4k9e+5wDSSpz/nWuKDr1M8WkzT7cNs=; b=MEWwZsoRdJAny7fCejlkbGkXOc+YddOF3rEu75d8Gx4VbGNoJQhSwQSj LYEOmcnk1jQqXcSE6CiWSCREOGqjHm5GPFO7L8Cncvg69W0LrIzxifQOK dFazQNtXM/iLL6OHUljZCjz7aJZ8Kc7fse1OcOYGR6gtinWBQl82Y/e2r K0LBB4ZWyK1TApxAn8ocYYAf73+xjUURY+yfvBK0CcLyr16kB0WIc+txv fKkwbxVXToe0PHgEu8qrmULwy2OMG51JyezJuv7vofy6mWSCS4/+TTaHN N6BIdlb1JMb97iy2FgNcpB5KDifQRDCz9wYbZcxQmcqcg60VAdWVxqX1J Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584885" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584885" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873035" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873035" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:03 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 06/13] ASoC: codecs: rt1318-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:44:01 +0800 Message-Id: <20230324014408.1677505-7-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: 2PBUCPVZDP5Q5265HQMPPHNTMDGRVZPM X-Message-ID-Hash: 2PBUCPVZDP5Q5265HQMPPHNTMDGRVZPM X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt1318-sdw.c | 30 +++++++----------------------- sound/soc/codecs/rt1318-sdw.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt1318-sdw.c b/sound/soc/codecs/rt1318-sdw.c index c32d8ae77981..795accedc22c 100644 --- a/sound/soc/codecs/rt1318-sdw.c +++ b/sound/soc/codecs/rt1318-sdw.c @@ -562,19 +562,7 @@ static const struct snd_soc_dapm_route rt1318_dapm_routes[] = { static int rt1318_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -582,11 +570,7 @@ static int rt1318_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt1318_sdw_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream, @@ -598,14 +582,14 @@ static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream, struct sdw_stream_config stream_config; struct sdw_port_config port_config; enum sdw_data_direction direction; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval, port, num_channels, ch_mask; unsigned int sampling_rate; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt1318->sdw_slave) @@ -633,7 +617,7 @@ static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream, port_config.num = port; retval = sdw_stream_add_slave(rt1318->sdw_slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -679,13 +663,13 @@ static int rt1318_sdw_pcm_hw_free(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct rt1318_sdw_priv *rt1318 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt1318->sdw_slave) return -EINVAL; - sdw_stream_remove_slave(rt1318->sdw_slave, stream->sdw_stream); + sdw_stream_remove_slave(rt1318->sdw_slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt1318-sdw.h b/sound/soc/codecs/rt1318-sdw.h index 4d7ac9c4bd8d..85918c184f16 100644 --- a/sound/soc/codecs/rt1318-sdw.h +++ b/sound/soc/codecs/rt1318-sdw.h @@ -94,8 +94,4 @@ struct rt1318_sdw_priv { bool first_hw_init; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - #endif /* __RT1318_SDW_H__ */ From patchwork Fri Mar 24 01:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666562 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 5DE2EC74A5B for ; Fri, 24 Mar 2023 01:35:13 +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 3185AED8; Fri, 24 Mar 2023 02:34:21 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3185AED8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621711; bh=rsdH95fTZ+MaDeA+rdXlZpK6j3fd2DH3eoQEbAG4WgA=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=qWKZ3+vtsiUQEPvt4fE7/P5o1QZU/BeePpWlYOoCEcPRiLLkh19P+KaMnP7dktM10 Dm7w8v/pwkQAkBFNc4033qXG+6ZZc7Be/uH7XQznpo9jp3z3cK0CYFPjYhN7Wx3KuX ZgOq2jcRiIvvzlCuKYFED5AAWtprY0eqXEGAwTgg= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 282B4F804B1; Fri, 24 Mar 2023 02:33:36 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7E165F8027B; Fri, 24 Mar 2023 02:33:31 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 80F27F80520 for ; Fri, 24 Mar 2023 02:29:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 80F27F80520 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=RPUekvpT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621348; x=1711157348; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rsdH95fTZ+MaDeA+rdXlZpK6j3fd2DH3eoQEbAG4WgA=; b=RPUekvpT08s+xyf0W1c+Q14zlyNnsJcZv8R0JElIKu0DovJsLBVz3JSi b2/s7iMQdKHT4YN32ueBxkrIjaGPLMdiKCwzC8H0/1ysMpFU8+uf2kRiP ZRvn3h1BdYSZb+twTnLqB6ijpvKc4sM9jyCpHbipQCX8C5gB45a24uHLo EK1ggbl6X47ghqqIvf8YBp8fpp5OWgKn0kPte01RJTVVowehC/Vve7BXY njCzSVsEY3R7YK+aKqDSsCTPcRgOGkjGsRWOVGC8ttratdIaRR9hEb5aX rGlLZWG0oFf/fxrz+fDclfF7/AyUUj8RipyOZkR4k6g87KrIZ8120wAFv w==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584890" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584890" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873044" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873044" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:05 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 07/13] ASoC: codecs: rt700-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:44:02 +0800 Message-Id: <20230324014408.1677505-8-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: NSJXWY6HMBTBWSVN72DX5IJGPMR2RGFI X-Message-ID-Hash: NSJXWY6HMBTBWSVN72DX5IJGPMR2RGFI X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt700.c | 30 +++++++----------------------- sound/soc/codecs/rt700.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt700.c b/sound/soc/codecs/rt700.c index 659ce26e9f3b..a04b9246256b 100644 --- a/sound/soc/codecs/rt700.c +++ b/sound/soc/codecs/rt700.c @@ -875,19 +875,7 @@ static const struct snd_soc_component_driver soc_codec_dev_rt700 = { static int rt700_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -895,11 +883,7 @@ static int rt700_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt700_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt700_pcm_hw_params(struct snd_pcm_substream *substream, @@ -910,14 +894,14 @@ static int rt700_pcm_hw_params(struct snd_pcm_substream *substream, struct rt700_priv *rt700 = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; unsigned int val = 0; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt700->slave) @@ -944,7 +928,7 @@ static int rt700_pcm_hw_params(struct snd_pcm_substream *substream, } retval = sdw_stream_add_slave(rt700->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -991,13 +975,13 @@ static int rt700_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt700_priv *rt700 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt700->slave) return -EINVAL; - sdw_stream_remove_slave(rt700->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt700->slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt700.h b/sound/soc/codecs/rt700.h index bed9d1de6d5b..93c44005d38c 100644 --- a/sound/soc/codecs/rt700.h +++ b/sound/soc/codecs/rt700.h @@ -27,10 +27,6 @@ struct rt700_priv { bool disable_irq; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - /* NID */ #define RT700_AUDIO_FUNCTION_GROUP 0x01 #define RT700_DAC_OUT1 0x02 From patchwork Fri Mar 24 01:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666938 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 672FDC6FD1C for ; Fri, 24 Mar 2023 01:35:15 +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 8A6BAEDB; Fri, 24 Mar 2023 02:34:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8A6BAEDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621712; bh=JmvCMuX6e+m5zMDfnYICrToLMhkiiVCRyDfYnN8XDzc=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Gp4T4v2a1H7lugu9NPurjtqS+O+VV2+II1buUbS73JLV1rNd2QpLF2hZPzTO6mqa/ nggJFO6gRWaOvxB0ys3ji7WIaIvZ2rVA/fBCIk14yiZicN1tl3+OT0HWZGfSYjW9zt TEx+Ddm2AI9l+UTreo12ckwkzgSb7NrT2dPNmHjc= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B9A2CF8053D; Fri, 24 Mar 2023 02:33:38 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C9AD6F8052E; Fri, 24 Mar 2023 02:33:34 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 B6822F804B1 for ; Fri, 24 Mar 2023 02:29:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B6822F804B1 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=F2DX2Zd5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621351; x=1711157351; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JmvCMuX6e+m5zMDfnYICrToLMhkiiVCRyDfYnN8XDzc=; b=F2DX2Zd5E5pV0RpA/8i2Nny72JX8uUdIbQ0czgyCG+rVoI4vRRp+bnMy cnhXgmU0oZ2dgIC+QjBsEV80hB8YVlJ0/4rBXVoiuOejB1wZrq1ZJyEPH uETwZM+JeETFwBzOJAjRtuhY5lygJld79yFPgm4QmeCB5o2zCLafSMY9J 8hw113a3/grO0uCQ66oXKArAtiJzCeSJKOKWLip3z4gZ1Q6vfw7qeWMZk QcQCa3S2BoUJyRkLzJ1A3ZTgARYNTnqputX3nQ6vLGqx+l7sWj4dWlRV1 a6Eq+ZIsGsvoGxvpExKq45I2g3PUqeUQZlxR6w9kytSShqKz2HHQnP4oA w==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584894" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584894" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873112" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873112" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:06 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 08/13] ASoC: codecs: rt711-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:44:03 +0800 Message-Id: <20230324014408.1677505-9-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: OFPM72IHSZUV5MLFWJGVO742KSEJRCZ5 X-Message-ID-Hash: OFPM72IHSZUV5MLFWJGVO742KSEJRCZ5 X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt711.c | 30 +++++++----------------------- sound/soc/codecs/rt711.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt711.c b/sound/soc/codecs/rt711.c index 862f50950565..af53cbcc7bf2 100644 --- a/sound/soc/codecs/rt711.c +++ b/sound/soc/codecs/rt711.c @@ -964,19 +964,7 @@ static const struct snd_soc_component_driver soc_codec_dev_rt711 = { static int rt711_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -984,11 +972,7 @@ static int rt711_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt711_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt711_pcm_hw_params(struct snd_pcm_substream *substream, @@ -999,14 +983,14 @@ static int rt711_pcm_hw_params(struct snd_pcm_substream *substream, struct rt711_priv *rt711 = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; unsigned int val = 0; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt711->slave) @@ -1027,7 +1011,7 @@ static int rt711_pcm_hw_params(struct snd_pcm_substream *substream, } retval = sdw_stream_add_slave(rt711->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -1075,13 +1059,13 @@ static int rt711_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt711_priv *rt711 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt711->slave) return -EINVAL; - sdw_stream_remove_slave(rt711->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt711->slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt711.h b/sound/soc/codecs/rt711.h index f50f8c8d0934..b31351f11df9 100644 --- a/sound/soc/codecs/rt711.h +++ b/sound/soc/codecs/rt711.h @@ -29,10 +29,6 @@ struct rt711_priv { bool disable_irq; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - /* NID */ #define RT711_AUDIO_FUNCTION_GROUP 0x01 #define RT711_DAC_OUT2 0x03 From patchwork Fri Mar 24 01:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666939 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 A6CC5C74A5B for ; Fri, 24 Mar 2023 01:34:45 +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 988BFEC9; Fri, 24 Mar 2023 02:33:53 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 988BFEC9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621683; bh=a0Hd+9i5i1nzEknPIsiDafrA0TcSFlMSYteGFBuA59M=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=i33kubrml1uyw5/LGGgroLD7vSg7uxuyPn2Br62QXSZzcmrlW5y/5p489YwPz6GrN 3tNURKkSzLSaaGnn8iRVyFI3f441/Zy3/ix2IrRSneZ8uGC4B0AUVAm7xbukLXC1wi hMFGDCqn7l/zP8iy1O7lO0qbeRV1FHYxZwkbYi1o= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B8AB2F8024E; Fri, 24 Mar 2023 02:33:31 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C25D5F800C9; Fri, 24 Mar 2023 02:33:27 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 C9B0AF80527 for ; Fri, 24 Mar 2023 02:29:11 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C9B0AF80527 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Z6C3/9NK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621353; x=1711157353; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a0Hd+9i5i1nzEknPIsiDafrA0TcSFlMSYteGFBuA59M=; b=Z6C3/9NK36W0TenuReiBLPf0DpjIyQf3bMmcIQvoI2tkcnxiru9ABC17 BYoT2KTMb0PiVTpihlGIiO4hxa8YBdO1UBCPp+O+b6GAiKDomw/nYgBfW ggWU9RDhOHaNh1CEYYIK4tLJ9v8GfWAnuPZZGj7vwOrALovWLYKvIDBrt EtPwtZ+kEMEw9+XgfP+li/kGNZkdS3g1d74DMF/eb3/BtBIepYlKvG61P Y6Tvm4ihmMg/pPfisJfUBkyuQDxs7+Lrbz89p3l93PK6Ft1Ct4EedSTdj BLY4MXukrjyW31wG032W03b76E4V88pYEqgGmYMnrTf94qlGwId5UKgEL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584901" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584901" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873122" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873122" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:08 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 09/13] ASoC: codecs: rt711-sdca: simplify set_stream Date: Fri, 24 Mar 2023 09:44:04 +0800 Message-Id: <20230324014408.1677505-10-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: SKB5YY4W6CVQZYQRV3L7ADUHHTSQHZT6 X-Message-ID-Hash: SKB5YY4W6CVQZYQRV3L7ADUHHTSQHZT6 X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt711-sdca.c | 30 +++++++----------------------- sound/soc/codecs/rt711-sdca.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt711-sdca.c b/sound/soc/codecs/rt711-sdca.c index c65abe812a4c..07640d2f6e56 100644 --- a/sound/soc/codecs/rt711-sdca.c +++ b/sound/soc/codecs/rt711-sdca.c @@ -1237,19 +1237,7 @@ static const struct snd_soc_component_driver soc_sdca_dev_rt711 = { static int rt711_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -1257,11 +1245,7 @@ static int rt711_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt711_sdca_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt711_sdca_pcm_hw_params(struct snd_pcm_substream *substream, @@ -1272,14 +1256,14 @@ static int rt711_sdca_pcm_hw_params(struct snd_pcm_substream *substream, struct rt711_sdca_priv *rt711 = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; unsigned int sampling_rate; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt711->slave) @@ -1300,7 +1284,7 @@ static int rt711_sdca_pcm_hw_params(struct snd_pcm_substream *substream, } retval = sdw_stream_add_slave(rt711->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -1351,13 +1335,13 @@ static int rt711_sdca_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt711_sdca_priv *rt711 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt711->slave) return -EINVAL; - sdw_stream_remove_slave(rt711->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt711->slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt711-sdca.h b/sound/soc/codecs/rt711-sdca.h index 10e3c801b813..22076f268577 100644 --- a/sound/soc/codecs/rt711-sdca.h +++ b/sound/soc/codecs/rt711-sdca.h @@ -36,10 +36,6 @@ struct rt711_sdca_priv { bool fu1e_dapm_mute, fu1e_mixer_l_mute, fu1e_mixer_r_mute; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - /* NID */ #define RT711_AUDIO_FUNCTION_GROUP 0x01 #define RT711_DAC_OUT2 0x03 From patchwork Fri Mar 24 01:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666941 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 46240C74A5B for ; Fri, 24 Mar 2023 01:32:40 +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 725F9ECA; Fri, 24 Mar 2023 02:31:48 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 725F9ECA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621558; bh=XogbEGQswLLwbWo+zFayUbHp660Ev5saiURsiWedWB8=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=QCMc1uytgSiiRLGC83i9DvOhvvN1yDBWFhnCGNpvVBJUuMdZg5drF2LgL5ql6o5Mp avfdY5+qM41gD3DSQCy2pVjchFzSFOCCB8qJXPVzeSktv4oOj+b8yuTsUE+aVjH+m8 r9DrepU6BzA1IB/1ZJUKKEfLkRPfJ0lNsG3yTxaM= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 18729F8057D; Fri, 24 Mar 2023 02:29:53 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E4F8EF8057E; Fri, 24 Mar 2023 02:29:47 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 11372F8027B for ; Fri, 24 Mar 2023 02:29:12 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 11372F8027B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Js76HBpl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621355; x=1711157355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XogbEGQswLLwbWo+zFayUbHp660Ev5saiURsiWedWB8=; b=Js76HBplKrLFKHklqsTkHWNC+VFHhvcXSwfhsHWGhxPnTNuNAwv2030f 1fqTr0dF/ednWPEfB1HoLHLcY1viMtYVauLQT+NBW53WGQOcNighOBR7d 6+/Kx3YQChOuzUICdvrm4c4yA7a5eOdmZBuEfxIZ94/mgOFAI7TCnZgep v3ZWfNiLj82ayJi7Ivlx7BNwe2MgXLG+fdEOxtCrRKBIoYK46slv+A1tD ZKO2JsECTvm2PgvMQlkH1/9UdxE92A17sCox9K6bwnf7yFjd0Nf5HbRQ0 wzqjE1wh7BaWUcNR3xB8DECSTxmdFEJSbrMM8Vxc4vvZu97OsOyvutM/s g==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584909" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584909" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873132" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873132" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:10 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 10/13] ASoC: codecs: rt712-sdca: simplify set_stream Date: Fri, 24 Mar 2023 09:44:05 +0800 Message-Id: <20230324014408.1677505-11-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: CLYE6CVMOKEB3EKFW67O75EGZJF4G2J5 X-Message-ID-Hash: CLYE6CVMOKEB3EKFW67O75EGZJF4G2J5 X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt712-sdca.c | 30 +++++++----------------------- sound/soc/codecs/rt712-sdca.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt712-sdca.c b/sound/soc/codecs/rt712-sdca.c index 8d2fa769bb2e..89d245655ca4 100644 --- a/sound/soc/codecs/rt712-sdca.c +++ b/sound/soc/codecs/rt712-sdca.c @@ -992,19 +992,7 @@ static const struct snd_soc_component_driver soc_sdca_dev_rt712 = { static int rt712_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -1012,11 +1000,7 @@ static int rt712_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt712_sdca_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, @@ -1028,14 +1012,14 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, struct sdw_stream_config stream_config; struct sdw_port_config port_config; enum sdw_data_direction direction; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval, port, num_channels; unsigned int sampling_rate; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt712->slave) @@ -1068,7 +1052,7 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, port_config.num = port; retval = sdw_stream_add_slave(rt712->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -1128,13 +1112,13 @@ static int rt712_sdca_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt712_sdca_priv *rt712 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt712->slave) return -EINVAL; - sdw_stream_remove_slave(rt712->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt712->slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt712-sdca.h b/sound/soc/codecs/rt712-sdca.h index cf647162f9da..c6a94a23f46e 100644 --- a/sound/soc/codecs/rt712-sdca.h +++ b/sound/soc/codecs/rt712-sdca.h @@ -40,10 +40,6 @@ struct rt712_sdca_priv { bool fu0f_mixer_r_mute; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - /* NID */ #define RT712_VENDOR_REG 0x20 #define RT712_VENDOR_CALI 0x58 From patchwork Fri Mar 24 01:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666564 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 1CC0AC74A5B for ; Fri, 24 Mar 2023 01:32:58 +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 05D98EBE; Fri, 24 Mar 2023 02:32:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 05D98EBE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621576; bh=EhPGLULuW9pAHe2m6xpGbV+FDNHJ7OCZ9/lWWPOGb14=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=hnaB432lNoPISyRDSMz/ZPeTE4jjKxNYCrfAAm+mEQFlxnwN0+vEdWONSHKBt2lp3 H+mUAShOMQ/litllTyj/eaK4BA6Dm/zhHNpC/f7tz33FUXDvOyeM9w5+0O9nroAHDp pj+YCQLw3MilW1sgCJUL29sTWctwptF6WMX56jZA= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 68AAFF80588; Fri, 24 Mar 2023 02:29:57 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2EC6AF8057D; Fri, 24 Mar 2023 02:29:51 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 3BBD5F80093 for ; Fri, 24 Mar 2023 02:29:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3BBD5F80093 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=A3DW2COH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621357; x=1711157357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EhPGLULuW9pAHe2m6xpGbV+FDNHJ7OCZ9/lWWPOGb14=; b=A3DW2COHPlbxWRvIMhzjLLX15lPHm0DO9UMK26l0AO/pt9CEf1G6SYHb ds1O7bY7tZdEmHICKisnPFOR+607NWnI8S1oSX1rSJ4gKu8i5jmiBdUdb oH2Ur6pkQ8P3eLTUdAM1bHF7ko/H1IiEkyrzL/lh9oyASI8QfSb/XZ0eF VJMyhN1eIDwEBLm3yvaU4RpsPb+ZKKM2Vw8cwMbGizusy52Bg7zcPyJ/5 +sJyzCg9wcgi0G96ePGpxQY2gV2t7Q4myezvMwEJEvVC93Vu0EGWsi8HP boXmVT/g4t8WwWdT3F4vuC1uAAXAiqisu0JO8tburSl6rDdqAruz2wAT1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584915" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584915" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873144" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873144" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:12 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 11/13] ASoC: codecs: rt715: simplify set_stream Date: Fri, 24 Mar 2023 09:44:06 +0800 Message-Id: <20230324014408.1677505-12-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: PZD4QAVMHTKIW5VZ7FM6LXTLWWJNY3AT X-Message-ID-Hash: PZD4QAVMHTKIW5VZ7FM6LXTLWWJNY3AT X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt715.c | 30 +++++++----------------------- sound/soc/codecs/rt715.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt715.c b/sound/soc/codecs/rt715.c index c6dd9df7be45..6c2e165dd621 100644 --- a/sound/soc/codecs/rt715.c +++ b/sound/soc/codecs/rt715.c @@ -765,19 +765,7 @@ static int rt715_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -786,11 +774,7 @@ static void rt715_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt715_pcm_hw_params(struct snd_pcm_substream *substream, @@ -801,13 +785,13 @@ static int rt715_pcm_hw_params(struct snd_pcm_substream *substream, struct rt715_priv *rt715 = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; unsigned int val = 0; - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt715->slave) @@ -830,7 +814,7 @@ static int rt715_pcm_hw_params(struct snd_pcm_substream *substream, } retval = sdw_stream_add_slave(rt715->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -893,13 +877,13 @@ static int rt715_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt715_priv *rt715 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt715->slave) return -EINVAL; - sdw_stream_remove_slave(rt715->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt715->slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt715.h b/sound/soc/codecs/rt715.h index 25dba61f1760..17a8d041c1c3 100644 --- a/sound/soc/codecs/rt715.h +++ b/sound/soc/codecs/rt715.h @@ -27,10 +27,6 @@ struct rt715_priv { unsigned int kctl_8ch_vol_ori[8]; }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - /* NID */ #define RT715_AUDIO_FUNCTION_GROUP 0x01 #define RT715_MIC_ADC 0x07 From patchwork Fri Mar 24 01:44:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666940 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 0BAC6C74A5B for ; Fri, 24 Mar 2023 01:33:11 +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 09A1DEDB; Fri, 24 Mar 2023 02:32:19 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 09A1DEDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621589; bh=o4qd2sv2ZOppsjBTKo/y1CYVg/dHsho3gT1BEbOKJc8=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=RuwDy4S2BTXB7s96oGRqOOLZohyGwSdChYI15QAtUzj1YnamB/JIMsvJqhJGSO7mE 98q2yTg75zbr/GLnPLEQ8WRA3uYy/KoEa6dLLEPRmdAnsMsJfPTbeFLsidInU/D0wY s5ArUtoycRFJ0t3+BOGFj4AIQU0WI8Koy116pUno= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 8B4D3F805A8; Fri, 24 Mar 2023 02:30:00 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4CC83F80580; Fri, 24 Mar 2023 02:29:55 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 D67AAF80529 for ; Fri, 24 Mar 2023 02:29:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D67AAF80529 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=dADXlDTK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621358; x=1711157358; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o4qd2sv2ZOppsjBTKo/y1CYVg/dHsho3gT1BEbOKJc8=; b=dADXlDTKeO9uuSNPtKNQXD9rR/Vcpl0pi3sKRdZWQ84xY/3Z4ms1DVN8 p6icJEd1HsHPu7taE3i+dBGuqviYnu7crCRG2TTbWjRRUqHGawlnoDO8W Awy7i7XsaRKc03LUQJFcaDnZvdzBf3FWiOeLe8bCw+CKw6g2ykcDr5d5u HYoE1TwtU93EihBVYOBkcqZHNhM/uIziCusKQvO+Ne63lfEQWAp5juN7Z hEPuVbwTl+emp+PU6NCr9QXYifGLkX9jnpioWQ3syOZM5OVpGbBtAm+g2 EYapmJjnDT9kgWAvtYzGEjeIJ4ShvW//UUcgNPQfZ9AtrZIO+DagC3tVc A==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584928" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584928" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873150" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873150" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:14 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 12/13] ASoC: codecs: rt715-sdca: simplify set_stream Date: Fri, 24 Mar 2023 09:44:07 +0800 Message-Id: <20230324014408.1677505-13-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: 67ZHRPQCRXOOH4H2VSAL4E3XYJBBFSJR X-Message-ID-Hash: 67ZHRPQCRXOOH4H2VSAL4E3XYJBBFSJR X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt715-sdca.c | 30 +++++++----------------------- sound/soc/codecs/rt715-sdca.h | 4 ---- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt715-sdca.c b/sound/soc/codecs/rt715-sdca.c index 920510365fd7..b989f907784b 100644 --- a/sound/soc/codecs/rt715-sdca.c +++ b/sound/soc/codecs/rt715-sdca.c @@ -784,16 +784,7 @@ static const struct snd_soc_component_driver soc_codec_dev_rt715_sdca = { static int rt715_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct rt715_sdw_stream_data *stream; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -802,14 +793,7 @@ static void rt715_sdca_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct rt715_sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) - return; - snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt715_sdca_pcm_hw_params(struct snd_pcm_substream *substream, @@ -820,13 +804,13 @@ static int rt715_sdca_pcm_hw_params(struct snd_pcm_substream *substream, struct rt715_sdca_priv *rt715 = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct rt715_sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; unsigned int val; - stream = snd_soc_dai_get_dma_data(dai, substream); + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + if (!sdw_stream) return -EINVAL; if (!rt715->slave) @@ -851,7 +835,7 @@ static int rt715_sdca_pcm_hw_params(struct snd_pcm_substream *substream, } retval = sdw_stream_add_slave(rt715->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(component->dev, "Unable to configure port, retval:%d\n", retval); @@ -922,13 +906,13 @@ static int rt715_sdca_pcm_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt715_sdca_priv *rt715 = snd_soc_component_get_drvdata(component); - struct rt715_sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt715->slave) return -EINVAL; - sdw_stream_remove_slave(rt715->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt715->slave, sdw_stream); return 0; } diff --git a/sound/soc/codecs/rt715-sdca.h b/sound/soc/codecs/rt715-sdca.h index 90881b455ece..7577f3151934 100644 --- a/sound/soc/codecs/rt715-sdca.h +++ b/sound/soc/codecs/rt715-sdca.h @@ -37,10 +37,6 @@ struct rt715_sdca_priv { int kctl_8ch_orig[8]; }; -struct rt715_sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - struct rt715_sdca_kcontrol_private { unsigned int reg_base; unsigned int count; From patchwork Fri Mar 24 01:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Liao, Bard" X-Patchwork-Id: 666563 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 D7194C7619A for ; Fri, 24 Mar 2023 01:33:17 +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 A6755EDF; Fri, 24 Mar 2023 02:32:25 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A6755EDF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679621595; bh=WDhsEqG4VZdPy8eVjOW22Vlhck7ur3f3lTWKvWSSEwE=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CwGfAupo1DGmJLCAUlkehce2ExaPqH2xJwRKncGRofQdsVWfMm6pHsEDYdMg6WHhU F/zmGfhJGcjGiITdP8nEDe9z1WLKekHrxCAtI0SlEdg4eU6uLXLA3FRpD1E0UZfc03 +3RdfFOov7A9ir+X0vPoAnMhA4CeE7WUJCwo6t+k= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 14314F805AA; Fri, 24 Mar 2023 02:30:04 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 074D7F805A8; Fri, 24 Mar 2023 02:29:59 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 BABD1F8052E for ; Fri, 24 Mar 2023 02:29:18 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BABD1F8052E Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=kwtPo767 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679621360; x=1711157360; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WDhsEqG4VZdPy8eVjOW22Vlhck7ur3f3lTWKvWSSEwE=; b=kwtPo767OYXZKrnQ04Y+bVCGcrIHyKR/WL+VcDtHFugueD0pLvbuytW2 Iyiv3EQPJIta9dmHDHrr2xA1Bb44LvT1rfISTaeViZsgD5G4ccbdqSA/Y ANiHV/50y6f6nQDp51jyp/69L/ju4EqkpmpZ495CWauC4fz+Uj6kqCAhR nxOBDyO7vnaokHLobCYUk9ChZjOTDgTJFvnsxqLNOis5xJTTwWuTnkqzG WwZuyfrnsuns+BaNHkHIbeXLpF9/DIkgV4oKG+PZXnLDkTSBUMWJxBPSQ lUbp8ken3eoqEmLq/u0mkvecieXQqZe6y+30rJrEZG4QmIXLWaujVjTiJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="404584939" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="404584939" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="659873156" X-IronPort-AV: E=Sophos;i="5.98,286,1673942400"; d="scan'208";a="659873156" Received: from bard-ubuntu.sh.intel.com ([10.239.185.57]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2023 18:29:16 -0700 From: Bard Liao To: broonie@kernel.org, tiwai@suse.de Subject: [PATCH 13/13] ASoC: codecs: rt5682-sdw: simplify set_stream Date: Fri, 24 Mar 2023 09:44:08 +0800 Message-Id: <20230324014408.1677505-14-yung-chuan.liao@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> References: <20230324014408.1677505-1-yung-chuan.liao@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: QQCBTQ2RMWU2NH3E3PEKBUNTTI2B7GEW X-Message-ID-Hash: QQCBTQ2RMWU2NH3E3PEKBUNTTI2B7GEW X-MailFrom: yung-chuan.liao@linux.intel.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 CC: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com, vkoul@kernel.org, bard.liao@intel.com 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: From: Pierre-Louis Bossart Using a dynamic allocation to store a single pointer is not very efficient/useful. Worse, the memory is released in the SoundWire stream.c file, but still accessed in the DAI shutdown, leading to kmemleak reports. And last the API requires the previous stream information to be cleared when the argument is NULL. Simplify the code to address all 3 problems. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Péter Ujfalusi Reviewed-by: Rander Wang Signed-off-by: Bard Liao --- sound/soc/codecs/rt5682-sdw.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/rt5682-sdw.c b/sound/soc/codecs/rt5682-sdw.c index 5f80a5d59b65..23f17f70d7e9 100644 --- a/sound/soc/codecs/rt5682-sdw.c +++ b/sound/soc/codecs/rt5682-sdw.c @@ -88,26 +88,10 @@ static const struct regmap_config rt5682_sdw_indirect_regmap = { .reg_write = rt5682_sdw_write, }; -struct sdw_stream_data { - struct sdw_stream_runtime *sdw_stream; -}; - static int rt5682_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, int direction) { - struct sdw_stream_data *stream; - - if (!sdw_stream) - return 0; - - stream = kzalloc(sizeof(*stream), GFP_KERNEL); - if (!stream) - return -ENOMEM; - - stream->sdw_stream = sdw_stream; - - /* Use tx_mask or rx_mask to configure stream tag and set dma_data */ - snd_soc_dai_dma_data_set(dai, direction, stream); + snd_soc_dai_dma_data_set(dai, direction, sdw_stream); return 0; } @@ -115,11 +99,7 @@ static int rt5682_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream, static void rt5682_sdw_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { - struct sdw_stream_data *stream; - - stream = snd_soc_dai_get_dma_data(dai, substream); snd_soc_dai_set_dma_data(dai, substream, NULL); - kfree(stream); } static int rt5682_sdw_hw_params(struct snd_pcm_substream *substream, @@ -130,14 +110,14 @@ static int rt5682_sdw_hw_params(struct snd_pcm_substream *substream, struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config = {0}; - struct sdw_stream_data *stream; + struct sdw_stream_runtime *sdw_stream; int retval; unsigned int val_p = 0, val_c = 0, osr_p = 0, osr_c = 0; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - stream = snd_soc_dai_get_dma_data(dai, substream); - if (!stream) + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); + if (!sdw_stream) return -ENOMEM; if (!rt5682->slave) @@ -152,7 +132,7 @@ static int rt5682_sdw_hw_params(struct snd_pcm_substream *substream, port_config.num = 2; retval = sdw_stream_add_slave(rt5682->slave, &stream_config, - &port_config, 1, stream->sdw_stream); + &port_config, 1, sdw_stream); if (retval) { dev_err(dai->dev, "Unable to configure port\n"); return retval; @@ -246,13 +226,13 @@ static int rt5682_sdw_hw_free(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component); - struct sdw_stream_data *stream = + struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream); if (!rt5682->slave) return -EINVAL; - sdw_stream_remove_slave(rt5682->slave, stream->sdw_stream); + sdw_stream_remove_slave(rt5682->slave, sdw_stream); return 0; }