From: Kuninori Morimoto Subject: [PATCH resend 05/11] ASoC: soc-core: don't alloc memory carelessly when creating debugfs Date: 20 Aug 2019 14:05:06 +0900 Message-ID: <8736hw1lde.wl-kuninori.morimoto.gx@renesas.com> References: <87a7c41lf1.wl-kuninori.morimoto.gx@renesas.com> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by alsa1.perex.cz (Postfix) with ESMTP id 17154F805FC for ; Tue, 20 Aug 2019 07:05:06 +0200 (CEST) In-Reply-To: <87a7c41lf1.wl-kuninori.morimoto.gx@renesas.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To: Mark Brown Cc: Linux-ALSA , "Sridharan, Ranjani" List-Id: alsa-devel@alsa-project.org From: Kuninori Morimoto Current ALSA SoC might allocate debugfs name memory via kasprintf(), but, it is unnecessary and the code becoming very complex. Using local variable with appropriate size is enough. This patch uses 64byte local variable for it. Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan --- v2 -> v3 - add Ranjani's Reviewed-by sound/soc/soc-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0ed6576..6862abd 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -149,23 +149,19 @@ static const struct attribute_group *soc_dev_attr_groups[] = { #ifdef CONFIG_DEBUG_FS static void soc_init_component_debugfs(struct snd_soc_component *component) { + char name[64]; + if (!component->card->debugfs_card_root) return; - if (component->debugfs_prefix) { - char *name; - - name = kasprintf(GFP_KERNEL, "%s:%s", + if (component->debugfs_prefix) + snprintf(name, ARRAY_SIZE(name), "%s:%s", component->debugfs_prefix, component->name); - if (name) { - component->debugfs_root = debugfs_create_dir(name, - component->card->debugfs_card_root); - kfree(name); - } - } else { - component->debugfs_root = debugfs_create_dir(component->name, - component->card->debugfs_card_root); - } + else + snprintf(name, ARRAY_SIZE(name), "%s", component->name); + + component->debugfs_root = debugfs_create_dir(name, + component->card->debugfs_card_root); snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), component->debugfs_root); -- 2.7.4