Skip to contentSkip to conversation

ASoC: Ensure we generate a driver name

PATCH In review Mark Brown 2 participants 6 messages Sep 20, 2011

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 ASoC: Ensure we generate a driver name

Commit 873bd4c (ASoC: Don't set invalid name string to snd_card->driver field) broke generation of a driver name for all ASoC cards relying on the automatic generation of one. Fix this by using the old default with spaces replaced by underscores.

---
 sound/soc/soc-core.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/soc-core.c +14 -3
index 10e5cde..3096c0d 100644
@@ -30,6 +30,7 @@
 #include <linux/bitops.h>
 #include <linux/debugfs.h>
 #include <linux/platform_device.h>
+#include <linux/ctype.h>
 #include <linux/slab.h>
 #include <sound/ac97_codec.h>
 #include <sound/core.h>
@@ -1432,9 +1433,19 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
 		 "%s", card->name);
 	snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
 		 "%s", card->long_name ? card->long_name : card->name);
-	if (card->driver_name)
-		strlcpy(card->snd_card->driver, card->driver_name,
-			sizeof(card->snd_card->driver));
+	snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
+		 "%s", card->driver_name ? card->driver_name : card->name);
+	for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
+		switch (card->snd_card->driver[i]) {
+		case '_':
+		case '-':
+			break;
+		default:
+			if (!isalnum(card->snd_card->driver[i]))
+				card->snd_card->driver[i] = '_';
+			break;
+		}
+	}
 
 	if (card->late_probe) {
 		ret = card->late_probe(card);
Signature · 1 line
1.7.6.3
#1 lore raw

At Tue, 20 Sep 2011 13:58:34 +0100,

Quoted 24 lines · Mark Brown

Commit 873bd4c (ASoC: Don't set invalid name string to snd_card->driver field) broke generation of a driver name for all ASoC cards relying on the automatic generation of one. Fix this by using the old default with spaces replaced by underscores.

---
 sound/soc/soc-core.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/soc-core.c +1 -0
index 10e5cde..3096c0d 100644
@@ -30,6 +30,7 @@
 #include <linux/bitops.h>
 #include <linux/debugfs.h>
 #include <linux/platform_device.h>
+#include <linux/ctype.h>
 #include <linux/slab.h>
 #include <sound/ac97_codec.h>
 #include <sound/core.h>

sound/soc/soc-core.c static void snd_soc_instantiate_card(struct snd_soc_card *card) · line 1438

Quoted 9 lines
sound/soc/soc-core.c +3 -3
@@ -1432,9 +1433,19 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
 		 "%s", card->name);
 	snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
 		 "%s", card->long_name ? card->long_name : card->name);
-	if (card->driver_name)
-		strlcpy(card->snd_card->driver, card->driver_name,
-			sizeof(card->snd_card->driver));
+	snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
+		 "%s", card->driver_name ? card->driver_name : card->name);
+	for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {

Should check card->snd_card->driver[i] != 0 here, too.

thanks,

Takashi

Quoted 16 lines
sound/soc/soc-core.c +10 -0
+		switch (card->snd_card->driver[i]) {
+		case '_':
+		case '-':
+			break;
+		default:
+			if (!isalnum(card->snd_card->driver[i]))
+				card->snd_card->driver[i] = '_';
+			break;
+		}
+	}
 
 	if (card->late_probe) {
 		ret = card->late_probe(card);
Signature · 1 line
1.7.6.3
author
#2 lore raw
Quoted 7 lines · Takashi Iwai

sound/soc/soc-core.c static void snd_soc_instantiate_card(struct snd_soc_card *card) · line 1438

Quoted 3 lines · Mark Brown
sound/soc/soc-core.c +3 -0
+	snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
+		 "%s", card->driver_name ? card->driver_name : card->name);
+	for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {

Should check card->snd_card->driver[i] != 0 here, too.

*sigh* This sort of issue is why I'd prefer to just squash specific characters, especially given that we're just being random about what a valid character is.

#3 lore raw

At Tue, 20 Sep 2011 14:18:05 +0100,

Quoted 10 lines · Mark Brown
Quoted 7 lines · Takashi Iwai

sound/soc/soc-core.c static void snd_soc_instantiate_card(struct snd_soc_card *card) · line 1438

Quoted 3 lines · Mark Brown
sound/soc/soc-core.c +3 -0
+	snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
+		 "%s", card->driver_name ? card->driver_name : card->name);
+	for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {

Should check card->snd_card->driver[i] != 0 here, too.

Quoted 3 lines

*sigh* This sort of issue is why I'd prefer to just squash specific characters, especially given that we're just being random about what a valid character is.

Heh. Or just use a char *, such as

	char *p;
	...
	for (p = card->snd_card->driver; *p; p++) {
		if (*p != '_' && *p != '-' && !isalnum(*p))
			*p = '_';
	}

Takashi

author
#4 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

*sigh* This sort of issue is why I'd prefer to just squash specific characters, especially given that we're just being random about what a valid character is.

Quoted 8 lines

Heh. Or just use a char *, such as

	char *p;
	...
	for (p = card->snd_card->driver; *p; p++) {
		if (*p != '_' && *p != '-' && !isalnum(*p))
			*p = '_';
	}

I find that a bit less legible, and I do like the ARRAY_SIZE() check for the warm and fuzzies. It's more just the listing all the characters bit. Anyway, is the last version OK for you?

Acked-by
#5 lore raw

At Tue, 20 Sep 2011 14:52:28 +0100,

Quoted 17 lines · Mark Brown
Quoted 6 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

*sigh* This sort of issue is why I'd prefer to just squash specific characters, especially given that we're just being random about what a valid character is.

Quoted 8 lines

Heh. Or just use a char *, such as

	char *p;
	...
	for (p = card->snd_card->driver; *p; p++) {
		if (*p != '_' && *p != '-' && !isalnum(*p))
			*p = '_';
	}
Quoted 3 lines

I find that a bit less legible, and I do like the ARRAY_SIZE() check for the warm and fuzzies. It's more just the listing all the characters bit. Anyway, is the last version OK for you?

Yeah, take my ack if needed.

thanks,

Takashi