From patchwork Mon Oct 17 23:37:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 615690 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 AE0D8C4332F for ; Mon, 17 Oct 2022 23:39:05 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id E085C3EC9; Tue, 18 Oct 2022 01:38:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E085C3EC9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1666049944; bh=uCPc4X3Cy1vwQF2SALXpScB8bqnIer2dAMWzUOHP8mY=; h=From:Subject:To:In-Reply-To:References:Date:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vTlO5T7nXCSHRSHNmx6HluJZTqsurOKZY/cQFYLHLU1RlIoYFTjfDjlm4ZiDAvQh4 OnI9taeMb57OgyB5jrv9zn5eg1izkV5gk/9tuDgYOXqxk30LeiL42AX/X62zk42Gs/ VBjLHshJTGJX1Lg1KjItRrRy/wzLPur7sbyh/fjc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4F1F7F80566; Tue, 18 Oct 2022 01:37:22 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id AB8C9F80579; Tue, 18 Oct 2022 01:37:20 +0200 (CEST) Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2101.outbound.protection.outlook.com [40.107.114.101]) (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 DF62FF80535 for ; Tue, 18 Oct 2022 01:37:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DF62FF80535 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="R8Z5G1zL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WIGbCzNBXzkM8e+tGv2siYha8HLEbx2W1dexG2XzcmVpVn1+wWdGHVCo/bMiW+46DJ4ntYT80Kz2DZqiCfsV++QZDfkV4r4goRDd/zuqqceEZxKjPQne0k5WkplyErf59q4yk/vdnFD/yo8fhSNEGAdFcXgXhyVzTOGfMqtIxzDMA4j8CU/daeEKwWtgWkrouHRnOhng/6IdrrotbEZ4J1NDffkpxi97S0l0ghV9BFLSqQraEx84ASEbJlY0IDHdnL4b6w1K7SwQ4HJ/AsniFPDMLIBgZ1kF05WrYct//AU4rmXdGpqmERpy8Whq7R7udwXRFrwveGe8LO9xSx04FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yJqlDNStcANf59V0aGryaosmVkvOD34eJDigLAKmZJU=; b=bavTvPCPiF4dhamS2iTSDOnO4ptxXLGqkQ73nnN34Hk2h29KMYRLTiEgFPmyQfIagf7JAPPcjNYJjuvcRCuO8rzkVdhqII/WkXW+KCv99fOvh9zGZtwCdC3te6ty1xhILg9Wn3Jf2pmY2uEc8y8otdQoyR09HE/JamesP7clx8YKRUV/EuF6bVfSsZSgMqCTPQZ91nXPFR0sgmPBCv/J3V6qnM5fLxGbQQIUO+V9VE/XdD8KwEQ4Yj6Rji3cI+qzOZl66mNMgoo+x3RM1g/TgN7or8gpByjKayweEc/Wh1oJMw0Vl5cz/ULZSR4GV3JGgXeKeNFdJE/69EsPsGADww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=renesas.com; dmarc=pass action=none header.from=renesas.com; dkim=pass header.d=renesas.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yJqlDNStcANf59V0aGryaosmVkvOD34eJDigLAKmZJU=; b=R8Z5G1zLiaA8/i9mUbh5gC4bZi/0u0vcT/gAkjKjM1nd52/oeXQUOPYiGK4UmsuuzRiTKDdwngztKLjPjvToGOqb3DT4USWUI6qZuEXec74BhzfpxKuMitj5NcvaPLBDtt6sx68BvGyM2f9M/lPcspiZAC75IrIHmLRtkhCxA/w= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=renesas.com; Received: from OS3PR01MB8426.jpnprd01.prod.outlook.com (2603:1096:604:194::10) by OS3PR01MB8180.jpnprd01.prod.outlook.com (2603:1096:604:176::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Mon, 17 Oct 2022 23:37:09 +0000 Received: from OS3PR01MB8426.jpnprd01.prod.outlook.com ([fe80::8860:a9ae:8e74:ec53]) by OS3PR01MB8426.jpnprd01.prod.outlook.com ([fe80::8860:a9ae:8e74:ec53%6]) with mapi id 15.20.5723.033; Mon, 17 Oct 2022 23:37:09 +0000 Message-ID: <87sfjmowd6.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 07/11] ASoC: soc-dapm.c: cleanup snd_soc_dapm_new_dai() User-Agent: Wanderlust/2.15.9 Emacs/26.3 Mule/6.0 To: Mark Brown In-Reply-To: <8735bmqazf.wl-kuninori.morimoto.gx@renesas.com> References: <8735bmqazf.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 17 Oct 2022 23:37:09 +0000 X-ClientProxiedBy: TYCP286CA0098.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2b4::19) To OS3PR01MB8426.jpnprd01.prod.outlook.com (2603:1096:604:194::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3PR01MB8426:EE_|OS3PR01MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: 81ec86c1-faf0-455d-062e-08dab098824e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RjHV+4WsfbyGqemYeCBgXcpG0Xev1mZ/SWyhcWh7TcDTXFSWm6ZcrZT296oikepKl+HdoNrPfC4jAEM93L69PjtRJ84PFnVuAdL01D7m4GYzovWtjWs9g9Rlw+i+XnioaQuyn2T5O0QgP5qaVSHJej26HO19pEWc4zjoLTFuN4mSkoq8gqXNgSEO1dCEAKck8MxiR6jpTvKYAvtiHRXea97iXYgUZV3kgK30xIicmOL1z/5Q3VBSnPXx0nHX3CRkJSTHsjHfSiB4r3YmBfpv6U0RF0J9m+tuGal1U9qvUP9TyTYgjITrXf5OfLytgi6gUPc8B53nifblTlzB2T4bpYqW7Wz/NY/4CQwybUEX7X/dxRUhyHGZPAu0MXHZ4LDTYhfqoWpGA4fc6LJj4ZiCgLSWLiYREd0h95/B8RVnP4yHMh8poyBEK1HsmyyzE5VKHky/RvD+nTpy3rHIaIQEpTbWo/hpfsRkyxy/w9L8fFkLxdsPmSIqKf8x1kK3Yr1YkW0Sy4T9ZYD9OGrGRX1AyRpY7kQWcJX+kBsGq8ZiGkIiYVYa5CSDS/afUmkvVGT9/NtzFM/peEkTSA07bXqxcufQLMIPRIuw9XqSE/7Zkhqh62kMlgx+J4RVkegYexNfYGeyzuRxQMlBzHWSQZalYf9bnoN3kDTkpzyYe0RliJ4LQqpBAfQkpw45IQkkQrH0CKUqB3MK8O+9rQJah67HMSsuUfTZ4MaZm7T77zc+20gCFrLt9pfYIZeVJUBikHfsUryDjIVC9q0Upw8oib5mAg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:OS3PR01MB8426.jpnprd01.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(136003)(346002)(376002)(396003)(366004)(39860400002)(451199015)(36756003)(86362001)(5660300002)(38100700002)(2906002)(38350700002)(2616005)(186003)(83380400001)(316002)(6506007)(6512007)(478600001)(6486002)(26005)(6916009)(66946007)(66556008)(66476007)(41300700001)(4326008)(52116002)(8936002)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IPciCqdUwUoWkmXHpoznyMPqxSJXz/r5X4+J2k9qVZf+oWUAtxkJi8gDK/rkUes03YQA6tg0y375VzB4OYNzFS5a7Qa9hIp2S46lRiOXJHnhJxtLbnFbUUSI0KLICcC36uVT9DcIk/QsjDlNfbdSSdD/rU76zn+JQG62ybzLenEwikpyHQ8JprdnEb2CIWoJxwcqVmXdC4yE4yQ5viHUIUz5n9dOgLPUEtSB+KRBhZI1g+O89hgILyE03WiRh27nbzUp8ip0aL0ZYO8J6PJxZrZTWYTJ3KNwrHnxz+NCNzsW0HvONFmmed9gScfrrw9/+kZJJJT2u9QKVHhHa0fCb2w94msIGB9RhGRTU1Gf5kFmO08s8TDwv8EQrEX+wPBt33tU4bU+yo7P7wLjRGP1aX6CF4MQC8KkD4RvN8RorYOC3RWR6aQ0w0rqXEqIUDtW9uvYJGuWDIJFs0vtrJWUs4Kfrvn4lRchsKxB+vAwrxI5btAPTRzAy8GEv/L28HvaAMqiPG03vZb9259o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jdc7DCP9jTLAuy3ZhA= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81ec86c1-faf0-455d-062e-08dab098824e X-MS-Exchange-CrossTenant-AuthSource: OS3PR01MB8426.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 23:37:09.4796 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DSyLUSoToTmwCTAyB86O8rbQFjCfjCGexTtHPE9JGiikCwM0m2PlI35RRO9VnjfKpr3aF+W5s2p84qEnyrkgRQp8oF/S5I/7XP0iRyFRcV8QSGMovPVjYiq/RxFmRoBC X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3PR01MB8180 Cc: Linux-ALSA X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" From: Kuninori Morimoto snd_soc_dapm_new_dai() setups local variable "template" at (X) and (Y), which is used at (Z). But these are difficult to read. static struct snd_soc_dapm_widget * snd_soc_dapm_new_dai() { ... ^ template.reg = ... | template.id = ... (X) template.name = ... | template.event = ... | template.event_flags = ... v template.kcontrol_news = ... if (rtd->dai_link->num_params > 1) { ... ^ template.num_kcontrols = ... (Y) template.kcontrol_news = ... v ... } ... (Z) w = snd_soc_dapm_new_control_unlocked(..., &template); } And this function has error message, but not for all cases. This patch (1) setups "template" in one place, and indicate error message for all cases. This patch cleanup the code, but nothing changed for meaning. Signed-off-by: Kuninori Morimoto --- sound/soc/soc-dapm.c | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 764830a51d2d..92140a78573d 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -4130,56 +4130,53 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); struct snd_soc_dapm_widget template; struct snd_soc_dapm_widget *w; + const struct snd_kcontrol_new *kcontrol_news; + int num_kcontrols; const char **w_param_text; unsigned long private_value = 0; char *link_name; - int ret; + int ret = -ENOMEM; link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s", rtd->dai_link->name, id); if (!link_name) - return ERR_PTR(-ENOMEM); - - memset(&template, 0, sizeof(template)); - template.reg = SND_SOC_NOPM; - template.id = snd_soc_dapm_dai_link; - template.name = link_name; - template.event = snd_soc_dai_link_event; - template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | - SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD; - template.kcontrol_news = NULL; + goto name_fail; /* allocate memory for control, only in case of multiple configs */ + w_param_text = NULL; + kcontrol_news = NULL; + num_kcontrols = 0; if (rtd->dai_link->num_params > 1) { w_param_text = devm_kcalloc(card->dev, rtd->dai_link->num_params, sizeof(char *), GFP_KERNEL); - if (!w_param_text) { - ret = -ENOMEM; + if (!w_param_text) goto param_fail; - } - template.num_kcontrols = 1; - template.kcontrol_news = - snd_soc_dapm_alloc_kcontrol(card, - link_name, - rtd->dai_link->params, - rtd->dai_link->num_params, - w_param_text, &private_value); - if (!template.kcontrol_news) { - ret = -ENOMEM; + num_kcontrols = 1; + kcontrol_news = snd_soc_dapm_alloc_kcontrol(card, link_name, + rtd->dai_link->params, + rtd->dai_link->num_params, + w_param_text, &private_value); + if (!kcontrol_news) goto param_fail; - } - } else { - w_param_text = NULL; } + + memset(&template, 0, sizeof(template)); + template.reg = SND_SOC_NOPM; + template.id = snd_soc_dapm_dai_link; + template.name = link_name; + template.event = snd_soc_dai_link_event; + template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | + SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD; + template.kcontrol_news = kcontrol_news; + template.num_kcontrols = num_kcontrols; + dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); if (IS_ERR(w)) { ret = PTR_ERR(w); - dev_err(rtd->dev, "ASoC: Failed to create %s widget: %d\n", - link_name, ret); goto outfree_kcontrol_news; } @@ -4193,6 +4190,9 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card, rtd->dai_link->num_params, w_param_text); param_fail: devm_kfree(card->dev, link_name); +name_fail: + dev_err(rtd->dev, "ASoC: Failed to create %s-%s widget: %d\n", + rtd->dai_link->name, id, ret); return ERR_PTR(ret); }