From patchwork Thu Oct 26 11:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 738350 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 312EFC25B6B for ; Thu, 26 Oct 2023 11:37:26 +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 783DF827; Thu, 26 Oct 2023 13:36:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 783DF827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1698320244; bh=wNYMRIG5scyAdTJj4MaccPslwOpU48pDFon17ftDxSU=; h=From:To:Cc:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=c7SCrDWlA9fsFM9s4WZdwx+NRS5CKYXo3s921KfaOfxFc2I+hRvOnnfsgv57c4NsZ 6/2t88VKRI/q7YzR2iHHq903Zc0vkCXCrPWrrFS97K1i960l44HjUNwojVDrLePrax dLogi7Pj52qN5odzjkXhs7NPG8WoXmzrAkioIzUY= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1D967F80165; Thu, 26 Oct 2023 13:36:01 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 733B3F8010B; Thu, 26 Oct 2023 13:36:01 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9C2C3F8019B; Thu, 26 Oct 2023 13:35:56 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) (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 80EA5F8014B for ; Thu, 26 Oct 2023 13:35:47 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 80EA5F8014B 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=M5pGUWZW DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698320149; x=1729856149; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wNYMRIG5scyAdTJj4MaccPslwOpU48pDFon17ftDxSU=; b=M5pGUWZWf5zWGFTPmq5Fz/Ztu31Z/SHGNWhx2aM6JPERvvV51hUF/rj/ ZVMfTAq2yhIGv3SjihIPtXwbyW6n7NXDvbB2WRC5WZW09jsZDB9xYPObc 9LuMOLBbW7x7dFMJxNn0nRAnZySPxjHXLipPsB6h3EMjj6rVEekPoMQF0 4lXNpyLwh+0pITE1UrWV6G4MS2j8Y3BwCyZ1ZLxPHxCPOkWF3MD+1JhR0 BkHt1XBO8cIYtG0OyKcVOZSV3J3knp7/5g7vPPIi9tw0nv9quQywd+sCo QpmU2bMdUjfEE0+DfBlKC8PftEqPAvKwu8r7rkbSpbMGVL10S/I53ET6u w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="473760825" X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="473760825" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 04:35:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="417432" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orviesa002.jf.intel.com with ESMTP; 26 Oct 2023 04:35:05 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Mark Brown Cc: Cezary Rojewski , Takashi Iwai , Jaroslav Kysela , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, =?utf-8?q?Amadeus?= =?utf-8?q?z_S=C5=82awi=C5=84ski?= Subject: [PATCH] ASoC: dapm: Simplify widget clone Date: Thu, 26 Oct 2023 13:35:49 +0200 Message-Id: <20231026113549.1897368-1-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: EFN7G7IVE63O6VDAMSDOD5TBMYEUMD43 X-Message-ID-Hash: EFN7G7IVE63O6VDAMSDOD5TBMYEUMD43 X-MailFrom: amadeuszx.slawinski@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 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: New DAPM widgets are created based on a provided template. When cloning the data, the name and stream name also need to be cloned. Currently the data and the names are initialized in different places. Simplify the code by having entire initialization in one place. Reviewed-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński Reviewed-by: Charles Keepax --- sound/soc/soc-dapm.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) base-commit: 3edc85e3bfcb411da6e48a38e8de578f9fd71340 diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 4e2beda6f9bf..b0503bf050db 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -320,7 +320,8 @@ EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty); /* create a new dapm widget */ static inline struct snd_soc_dapm_widget *dapm_cnew_widget( - const struct snd_soc_dapm_widget *_widget) + const struct snd_soc_dapm_widget *_widget, + const char *prefix) { struct snd_soc_dapm_widget *w; @@ -328,13 +329,19 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget( if (!w) return NULL; - /* - * w->name is duplicated in caller, but w->sname isn't. - * Duplicate it here if defined - */ + if (prefix) + w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, _widget->name); + else + w->name = kstrdup_const(_widget->name, GFP_KERNEL); + if (!w->name) { + kfree(w); + return NULL; + } + if (_widget->sname) { w->sname = kstrdup_const(_widget->sname, GFP_KERNEL); if (!w->sname) { + kfree_const(w->name); kfree(w); return NULL; } @@ -3629,20 +3636,12 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, { enum snd_soc_dapm_direction dir; struct snd_soc_dapm_widget *w; - const char *prefix; int ret = -ENOMEM; - if ((w = dapm_cnew_widget(widget)) == NULL) + w = dapm_cnew_widget(widget, soc_dapm_prefix(dapm)); + if (!w) goto cnew_failed; - prefix = soc_dapm_prefix(dapm); - if (prefix) - w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); - else - w->name = kstrdup_const(widget->name, GFP_KERNEL); - if (!w->name) - goto name_failed; - switch (w->id) { case snd_soc_dapm_regulator_supply: w->regulator = devm_regulator_get(dapm->dev, widget->name); @@ -3767,7 +3766,6 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, dev_err_probe(dapm->dev, ret, "ASoC: Failed to request %s\n", w->name); kfree_const(w->name); -name_failed: kfree_const(w->sname); kfree(w); cnew_failed: