Skip to contentSkip to conversation

ASoC: Ensure we generate a card name

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

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 ASoC: Ensure we generate a card 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 |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
sound/soc/soc-core.c +5 -3
index 10e5cde..7e30c08 100644
@@ -1432,9 +1432,11 @@ 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++)
+		if (card->snd_card->driver[i] == ' ')
+			card->snd_card->driver[i] = '_';
 
 	if (card->late_probe) {
 		ret = card->late_probe(card);
Signature · 1 line
1.7.6.3
#1 lore raw

At Tue, 20 Sep 2011 11:42:21 +0100,

Quoted 7 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.

Better to replace any letter except [a-zA-Z0-9_] with '_' or drop them. Use isalnum(), for example.

thanks,

Takashi

Quoted 26 lines
---
 sound/soc/soc-core.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
sound/soc/soc-core.c +5 -3
index 10e5cde..7e30c08 100644
@@ -1432,9 +1432,11 @@ 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++)
+		if (card->snd_card->driver[i] == ' ')
+			card->snd_card->driver[i] = '_';
 
 	if (card->late_probe) {
 		ret = card->late_probe(card);
Signature · 1 line
1.7.6.3
author
#2 lore raw
Quoted 2 lines · Takashi Iwai

Better to replace any letter except [a-zA-Z0-9_] with '_' or drop them. Use isalnum(), for example.

What *are* the rules? The documentation says "driver name" which isn't verbose...

#3 lore raw

At Tue, 20 Sep 2011 12:03:56 +0100,

Quoted 8 lines · Mark Brown
Quoted 2 lines · Takashi Iwai

Better to replace any letter except [a-zA-Z0-9_] with '_' or drop them. Use isalnum(), for example.

What *are* the rules? The documentation says "driver name" which isn't verbose...

It's used as an id string, so you can guess.
Practically, it should be a single word, contain no dangerous letters that may screw up the parser.

Takashi

author
#4 lore raw
Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Mark Brown
Quoted 2 lines

Better to replace any letter except [a-zA-Z0-9_] with '_' or drop them. Use isalnum(), for example.

What *are* the rules? The documentation says "driver name" which isn't verbose...

It's used as an id string, so you can guess.
Practically, it should be a single word, contain no dangerous letters that may screw up the parser.

I'm inclined to just stick with the original patch then, I'd expect that anything that's problematic for the driver name is also going to be an issue in the main name field and it's a lot simpler to implement (we don't have isalnum() in kernel right now and you still need to handle _ and possibly -).

#5 lore raw

At Tue, 20 Sep 2011 13:19:14 +0100,

Quoted 14 lines · Mark Brown
Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Mark Brown
Quoted 2 lines

Better to replace any letter except [a-zA-Z0-9_] with '_' or drop them. Use isalnum(), for example.

What *are* the rules? The documentation says "driver name" which isn't verbose...

It's used as an id string, so you can guess.
Practically, it should be a single word, contain no dangerous letters that may screw up the parser.

Quoted 5 lines

I'm inclined to just stick with the original patch then, I'd expect that anything that's problematic for the driver name is also going to be an issue in the main name field and it's a lot simpler to implement (we don't have isalnum() in kernel right now and you still need to handle _ and possibly -).

The main name field isn't used by the parser. So it may contain special letters like parentheses or such.

And we have isalnum() in kernel, see include/linux/ctype.h.

Takashi

author
#6 lore raw
Quoted 2 lines · Takashi Iwai

The main name field isn't used by the parser. So it may contain special letters like parentheses or such.

It might not be used by ALSA but it's used by some userspaces to identify the card they're running on.

#7 lore raw

At Tue, 20 Sep 2011 13:56:46 +0100,

Quoted 8 lines · Mark Brown
Quoted 2 lines · Takashi Iwai

The main name field isn't used by the parser. So it may contain special letters like parentheses or such.

It might not be used by ALSA but it's used by some userspaces to identify the card they're running on.

The card->name can contain special letters. This has been so for over a decade, and won't be changed. Why now need to change this?

Takashi

author
#8 lore raw
Quoted 7 lines · Takashi Iwai
Quoted 2 lines · Mark Brown

It might not be used by ALSA but it's used by some userspaces to identify the card they're running on.

The card->name can contain special letters. This has been so for over a decade, and won't be changed. Why now need to change this?

I'm not suggesting that it should? To be honest I'm quite surprised that the alsa-lib code isn't able to cope with spaces in the driver name in the first places, I'd rather just fix the specific characters it doesn't like.

#9 lore raw

At Tue, 20 Sep 2011 14:20:02 +0100,

Quoted 11 lines · Mark Brown
Quoted 7 lines · Takashi Iwai
Quoted 2 lines · Mark Brown

It might not be used by ALSA but it's used by some userspaces to identify the card they're running on.

The card->name can contain special letters. This has been so for over a decade, and won't be changed. Why now need to change this?

I'm not suggesting that it should?

OK, then I misunderstood the context. It wasn't clear to me.

Quoted 4 lines

To be honest I'm quite surprised
that the alsa-lib code isn't able to cope with spaces in the driver name in the first places, I'd rather just fix the specific characters it doesn't like.

Spaces may be handled actually, but it'll become tricky by quoting. It's just like a shell script programming - spaces make harder to handle in the end. So, it should be avoided if possible.

Takashi