[alsa-devel] [PATCH] 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.
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com --- sound/soc/soc-core.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 10e5cde..7e30c08 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -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);
At Tue, 20 Sep 2011 11:42:21 +0100, Mark Brown wrote:
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.
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com
Better to replace any letter except [a-zA-Z0-9_] with '_' or drop them. Use isalnum(), for example.
thanks,
Takashi
sound/soc/soc-core.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 10e5cde..7e30c08 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -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);
-- 1.7.6.3
At Tue, 20 Sep 2011 12:03:56 +0100, Mark Brown wrote:
On Tue, Sep 20, 2011 at 12:58:11PM +0200, Takashi Iwai wrote:
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
On Tue, Sep 20, 2011 at 02:12:15PM +0200, Takashi Iwai wrote:
Mark Brown wrote:
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 -).
At Tue, 20 Sep 2011 13:19:14 +0100, Mark Brown wrote:
On Tue, Sep 20, 2011 at 02:12:15PM +0200, Takashi Iwai wrote:
Mark Brown wrote:
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 -).
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
At Tue, 20 Sep 2011 13:56:46 +0100, Mark Brown wrote:
On Tue, Sep 20, 2011 at 02:51:12PM +0200, Takashi Iwai wrote:
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
On Tue, Sep 20, 2011 at 03:02:22PM +0200, Takashi Iwai wrote:
Mark Brown wrote:
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.
At Tue, 20 Sep 2011 14:20:02 +0100, Mark Brown wrote:
On Tue, Sep 20, 2011 at 03:02:22PM +0200, Takashi Iwai wrote:
Mark Brown wrote:
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.
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
participants (2)
-
Mark Brown
-
Takashi Iwai