[PATCH] ASoC: soc-core: Remove name length truncation

Tom Eccles tom.eccles at codethink.co.uk
Thu Apr 9 14:21:50 CEST 2020


snd_soc_dai.name and snd_soc_component.name are a simplified version of
the parent device's name, truncated to NAME_SIZE characters (see
fmt_single_name). NAME_SIZE was 32 characters.

Some device names may share a common prefix longer than 32 characters,
which leads to non-unique snd_soc_dai.name and snd_soc_component.name.
When these are added to debugfs, the .name is used for the file. If the
names are not unique, adding to debugfs fails.

Instead, dynamically allocate name buffers to be as long as needed.

Signed-off-by: Tom Eccles <tom.eccles at codethink.co.uk>
---
 sound/soc/soc-core.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 843b8b1c89d4..7803222ede54 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -43,8 +43,6 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/asoc.h>
 
-#define NAME_SIZE	32
-
 static DEFINE_MUTEX(client_mutex);
 static LIST_HEAD(component_list);
 static LIST_HEAD(unbind_card_list);
@@ -2291,13 +2289,15 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
  */
 static char *fmt_single_name(struct device *dev, int *id)
 {
-	char *found, name[NAME_SIZE];
+	char *found, *name;
 	int id1, id2;
 
 	if (dev_name(dev) == NULL)
 		return NULL;
 
-	strlcpy(name, dev_name(dev), NAME_SIZE);
+	name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
+	if (!name)
+		return NULL;
 
 	/* are we a "%s.%d" name (platform and SPI components) */
 	found = strstr(name, dev->driver->name);
@@ -2313,20 +2313,23 @@ static char *fmt_single_name(struct device *dev, int *id)
 	} else {
 		/* I2C component devices are named "bus-addr" */
 		if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
-			char tmp[NAME_SIZE];
+			char *tmp;
 
 			/* create unique ID number from I2C addr and bus */
 			*id = ((id1 & 0xffff) << 16) + id2;
 
 			/* sanitize component name for DAI link creation */
-			snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name,
-				 name);
-			strlcpy(name, tmp, NAME_SIZE);
+			tmp = devm_kasprintf(dev, GFP_KERNEL, "%s.%s",
+				 dev->driver->name, name);
+			devm_kfree(dev, name);
+			if (!tmp)
+				return NULL;
+			name = tmp;
 		} else
 			*id = 0;
 	}
 
-	return devm_kstrdup(dev, name, GFP_KERNEL);
+	return name;
 }
 
 /*

base-commit: fff876253c1e1b329257ba33045195c93e25adcd
-- 
2.20.1



More information about the Alsa-devel mailing list