alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: Ensure we generate a driver name
@ 2011-09-20 12:58 Mark Brown
  2011-09-20 13:11 ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2011-09-20 12:58 UTC (permalink / raw)
  To: Takashi Iwai, Liam Girdwood; +Cc: alsa-devel, patches, 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.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 sound/soc/soc-core.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 10e5cde..3096c0d 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -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);
-- 
1.7.6.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-20 12:58 Mark Brown
@ 2011-09-20 13:11 ` Takashi Iwai
  2011-09-20 13:18   ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2011-09-20 13:11 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, patches, Liam Girdwood

At Tue, 20 Sep 2011 13:58:34 +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>
> ---
>  sound/soc/soc-core.c |   17 ++++++++++++++---
>  1 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index 10e5cde..3096c0d 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -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++) {

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


thanks,

Takashi

> +		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);
> -- 
> 1.7.6.3
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] ASoC: Ensure we generate a driver name
@ 2011-09-20 13:16 Mark Brown
  2011-09-21  5:09 ` Scott Jiang
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2011-09-20 13:16 UTC (permalink / raw)
  To: Takashi Iwai, Liam Girdwood; +Cc: alsa-devel, patches, 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.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 sound/soc/soc-core.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 10e5cde..bd20154 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -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,20 @@ 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 '-':
+		case '\0':
+			break;
+		default:
+			if (!isalnum(card->snd_card->driver[i]))
+				card->snd_card->driver[i] = '_';
+			break;
+		}
+	}
 
 	if (card->late_probe) {
 		ret = card->late_probe(card);
-- 
1.7.6.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-20 13:11 ` Takashi Iwai
@ 2011-09-20 13:18   ` Mark Brown
  2011-09-20 13:32     ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2011-09-20 13:18 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, patches, Liam Girdwood

On Tue, Sep 20, 2011 at 03:11:08PM +0200, Takashi Iwai wrote:
> Mark Brown wrote:

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-20 13:18   ` Mark Brown
@ 2011-09-20 13:32     ` Takashi Iwai
  2011-09-20 13:52       ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2011-09-20 13:32 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, patches, Liam Girdwood

At Tue, 20 Sep 2011 14:18:05 +0100,
Mark Brown wrote:
> 
> On Tue, Sep 20, 2011 at 03:11:08PM +0200, Takashi Iwai wrote:
> > Mark Brown wrote:
> 
> > > +	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.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-20 13:32     ` Takashi Iwai
@ 2011-09-20 13:52       ` Mark Brown
  2011-09-20 14:02         ` Takashi Iwai
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2011-09-20 13:52 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, patches, Liam Girdwood

On Tue, Sep 20, 2011 at 03:32:48PM +0200, Takashi Iwai wrote:
> Mark Brown wrote:

> > *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 = '_';
> 	}

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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-20 13:52       ` Mark Brown
@ 2011-09-20 14:02         ` Takashi Iwai
  0 siblings, 0 replies; 9+ messages in thread
From: Takashi Iwai @ 2011-09-20 14:02 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, patches, Liam Girdwood

At Tue, 20 Sep 2011 14:52:28 +0100,
Mark Brown wrote:
> 
> On Tue, Sep 20, 2011 at 03:32:48PM +0200, Takashi Iwai wrote:
> > Mark Brown wrote:
> 
> > > *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 = '_';
> > 	}
> 
> 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.

Acked-by: Takashi Iwai <tiwai@suse.de>


thanks,

Takashi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-20 13:16 [PATCH] ASoC: Ensure we generate a driver name Mark Brown
@ 2011-09-21  5:09 ` Scott Jiang
  2011-09-21 12:41   ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Scott Jiang @ 2011-09-21  5:09 UTC (permalink / raw)
  To: Mark Brown
  Cc: Takashi Iwai, uclinux-dist-devel, alsa-devel, patches,
	Liam Girdwood

2011/9/20 Mark Brown <broonie@opensource.wolfsonmicro.com>:
> 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 |   18 +++++++++++++++---
>  1 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index 10e5cde..bd20154 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -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,20 @@ 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 '-':
> +               case '\0':
> +                       break;
> +               default:
> +                       if (!isalnum(card->snd_card->driver[i]))
> +                               card->snd_card->driver[i] = '_';
> +                       break;
> +               }
> +       }
>
>        if (card->late_probe) {
>                ret = card->late_probe(card);
> --
If '\0', we should break out of loop?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ASoC: Ensure we generate a driver name
  2011-09-21  5:09 ` Scott Jiang
@ 2011-09-21 12:41   ` Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2011-09-21 12:41 UTC (permalink / raw)
  To: Scott Jiang
  Cc: Takashi Iwai, uclinux-dist-devel, alsa-devel, patches,
	Liam Girdwood

On Wed, Sep 21, 2011 at 01:09:30PM +0800, Scott Jiang wrote:
> 2011/9/20 Mark Brown <broonie@opensource.wolfsonmicro.com>:

> > +       for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
> > +               switch (card->snd_card->driver[i]) {
> > +               case '_':
> > +               case '-':
> > +               case '\0':
> > +                       break;
> > +               default:
> > +                       if (!isalnum(card->snd_card->driver[i]))
> > +                               card->snd_card->driver[i] = '_';
> > +                       break;
> > +               }
> > +       }

> If '\0', we should break out of loop?

It's really not worth the code complexity, we only run this once during
probe and the array is fixed size and small.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-09-21 12:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-20 13:16 [PATCH] ASoC: Ensure we generate a driver name Mark Brown
2011-09-21  5:09 ` Scott Jiang
2011-09-21 12:41   ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2011-09-20 12:58 Mark Brown
2011-09-20 13:11 ` Takashi Iwai
2011-09-20 13:18   ` Mark Brown
2011-09-20 13:32     ` Takashi Iwai
2011-09-20 13:52       ` Mark Brown
2011-09-20 14:02         ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).