[23/28] ASoC: soc-core: don't alloc memory carelessly when creating debugfs
diff mbox series

Message ID 874l2v2ie8.wl-kuninori.morimoto.gx@renesas.com
State New
Headers show
Series
  • ASoC: cleanup patches for soc-core
Related show

Commit Message

Kuninori Morimoto Aug. 6, 2019, 1:30 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current ALSA SoC might allocate debugfs name memory via kasprintf(),
but, it is grandiose and the code becoming very complex.
Using enough size local variable is very enough for this purpose.

This patch uses 64byte local variable for it.
It is very enough size for this purposeq.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-core.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

Comments

Pierre-Louis Bossart Aug. 6, 2019, 3:05 p.m. UTC | #1
On 8/5/19 8:30 PM, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> Current ALSA SoC might allocate debugfs name memory via kasprintf(),
> but, it is grandiose and the code becoming very complex.

grandiose sounds lyric. did you mean unnecessary?

> Using enough size local variable is very enough for this purpose.

Using local variable with appropriate size is enough.

> 
> This patch uses 64byte local variable for it.
> It is very enough size for this purposeq.

last sentence is redundant

> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>   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 c737349..bf3bda2 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -147,23 +147,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);
>

Patch
diff mbox series

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c737349..bf3bda2 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -147,23 +147,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);