Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexander E. Patrakov" <patrakov@gmail.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, "Alexander E. Patrakov" <patrakov@gmail.com>
Subject: [PATCH lib v2] Replace unsafe characters with _ in card name
Date: Mon, 29 Jun 2015 22:53:53 +0500	[thread overview]
Message-ID: <1435600433-15873-1-git-send-email-patrakov@gmail.com> (raw)

Otherwise, they get misinterpreted as argument separators
in USB-Audio PCM definitions, and thus prevent SPDIF blacklist entries
from working.

While at it, add my Logitec C910 webcam to the SPDIF blacklist.

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
---
v2: Fixed misplaced NULL check for tmp->u.string

 include/conf.h                |  1 +
 src/conf.c                    | 32 ++++++++++++++++++++++++++++++++
 src/conf/cards/USB-Audio.conf |  3 ++-
 src/confmisc.c                |  2 +-
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/include/conf.h b/include/conf.h
index ff270f6..087c05d 100644
--- a/include/conf.h
+++ b/include/conf.h
@@ -126,6 +126,7 @@ int snd_config_imake_integer(snd_config_t **config, const char *key, const long
 int snd_config_imake_integer64(snd_config_t **config, const char *key, const long long value);
 int snd_config_imake_real(snd_config_t **config, const char *key, const double value);
 int snd_config_imake_string(snd_config_t **config, const char *key, const char *ascii);
+int snd_config_imake_safe_string(snd_config_t **config, const char *key, const char *ascii);
 int snd_config_imake_pointer(snd_config_t **config, const char *key, const void *ptr);
 
 snd_config_type_t snd_config_get_type(const snd_config_t *config);
diff --git a/src/conf.c b/src/conf.c
index bb256e7..c6a83ee 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -2228,6 +2228,38 @@ int snd_config_imake_string(snd_config_t **config, const char *id, const char *v
 	return 0;
 }
 
+int snd_config_imake_safe_string(snd_config_t **config, const char *id, const char *value)
+{
+	int err;
+	snd_config_t *tmp;
+	char *c;
+
+	err = snd_config_make(&tmp, id, SND_CONFIG_TYPE_STRING);
+	if (err < 0)
+		return err;
+	if (value) {
+		tmp->u.string = strdup(value);
+		if (!tmp->u.string) {
+			snd_config_delete(tmp);
+			return -ENOMEM;
+		}
+
+		for (c = tmp->u.string; *c; c++) {
+			if (*c == ' ' || *c == '-' || *c == '_' ||
+				(*c >= '0' && *c <= '9') ||
+				(*c >= 'a' && *c <= 'z') ||
+				(*c >= 'A' && *c <= 'Z'))
+					continue;
+			*c = '_';
+		}
+	} else {
+		tmp->u.string = NULL;
+	}
+	*config = tmp;
+	return 0;
+}
+
+
 /**
  * \brief Creates a pointer configuration node with the given initial value.
  * \param[out] config The function puts the handle to the new node at
diff --git a/src/conf/cards/USB-Audio.conf b/src/conf/cards/USB-Audio.conf
index 031bee0..e365f29 100644
--- a/src/conf/cards/USB-Audio.conf
+++ b/src/conf/cards/USB-Audio.conf
@@ -57,7 +57,8 @@ USB-Audio.pcm.iec958_device {
 	"Scarlett 2i4 USB" 999
 	"Sennheiser USB headset" 999
 	"SWTOR Gaming Headset by Razer" 999
-	"USB Device 0x46d:0x992" 999
+	"USB Device 0x46d_0x821" 999
+	"USB Device 0x46d_0x992" 999
 }
 
 # Second iec958 device number, if any.
diff --git a/src/confmisc.c b/src/confmisc.c
index 1fb4f28..ae0275f 100644
--- a/src/confmisc.c
+++ b/src/confmisc.c
@@ -935,7 +935,7 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root,
 	}
 	err = snd_config_get_id(src, &id);
 	if (err >= 0)
-		err = snd_config_imake_string(dst, id,
+		err = snd_config_imake_safe_string(dst, id,
 					      snd_ctl_card_info_get_name(info));
       __error:
       	if (ctl)
-- 
2.4.4

             reply	other threads:[~2015-06-29 17:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29 17:53 Alexander E. Patrakov [this message]
2015-06-29 20:06 ` [PATCH lib v2] Replace unsafe characters with _ in card name Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435600433-15873-1-git-send-email-patrakov@gmail.com \
    --to=patrakov@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox