From patchwork Tue Jul 21 16:11:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 6837041 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 56C6C9F380 for ; Tue, 21 Jul 2015 16:11:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 77D25206CE for ; Tue, 21 Jul 2015 16:11:32 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 9CA0D20601 for ; Tue, 21 Jul 2015 16:11:30 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id D2F752650F7; Tue, 21 Jul 2015 18:11:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 223F5260575; Tue, 21 Jul 2015 18:11:21 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6A72C2605AF; Tue, 21 Jul 2015 18:11:19 +0200 (CEST) Received: from smtp-out-101.synserver.de (smtp-out-101.synserver.de [212.40.185.101]) by alsa0.perex.cz (Postfix) with ESMTP id 48EAE260575 for ; Tue, 21 Jul 2015 18:11:12 +0200 (CEST) Received: (qmail 21850 invoked by uid 0); 21 Jul 2015 16:11:12 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 21745 Received: from pd9e2f8cb.dip0.t-ipconnect.de (HELO lars-laptop.ad.analog.com) [217.226.248.203] by 217.119.54.96 with SMTP; 21 Jul 2015 16:11:11 -0000 From: Lars-Peter Clausen To: Mark Brown , Liam Girdwood Date: Tue, 21 Jul 2015 18:11:08 +0200 Message-Id: <1437495068-4104-2-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437495068-4104-1-git-send-email-lars@metafoo.de> References: <1437495068-4104-1-git-send-email-lars@metafoo.de> Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen Subject: [alsa-devel] [PATCH 2/2] ASoC: dapm: Avoid duplicating immutable strings X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP When creating a new widget from a template the name string of the template is duplicated for the newly created widget. This is necessary because in some cases the string might be stored on the stack or other volatile memory locations. But most of the time the string is static const data, which means it is possible to use it directly without having to worry that it might get freed or changed. Use kstrdup_const() to handle duplicating the string. This function is capable of detecting whether a string is immutable and if it is returns the input without duplicating it. This will slightly reduce the runtime memory footprint of DAPM and also speed up initialization. Signed-off-by: Lars-Peter Clausen --- sound/soc/soc-dapm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 7a57b01..7f834a0 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2332,7 +2332,7 @@ void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w) dapm_free_path(p); kfree(w->kcontrols); - kfree(w->name); + kfree_const(w->name); kfree(w); } @@ -3353,7 +3353,7 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, if (prefix) w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); else - w->name = kasprintf(GFP_KERNEL, "%s", widget->name); + w->name = kstrdup_const(widget->name, GFP_KERNEL); if (w->name == NULL) { kfree(w); return NULL;