alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Hui Wang <hui.wang@canonical.com>
To: alsa-devel@alsa-project.org, tiwai@suse.de, perex@perex.cz,
	kai.vehmanen@linux.intel.com
Subject: [RFC][PATCH v4 2/4] alsa: jack: adjust jack_kctl debugfs folder's name
Date: Mon, 11 Jan 2021 21:05:55 +0800	[thread overview]
Message-ID: <20210111130557.90208-3-hui.wang@canonical.com> (raw)
In-Reply-To: <20210111130557.90208-1-hui.wang@canonical.com>

We used jack_kctl->kctl.id as the folder's name, but there are some
characters which are not suitable for foler's name, for example, a
HDMI/DP audio jack id contains '/', ',', '=' and ' ', this patch will
remove them from folder's name.

Before applying patch, the folders look like:
'HDMI!DP,pcm=3 Jack'  'Headphone Jack'  'Mic Jack'

After applying the patch, the folders look like:
HDMIDPpcm3Jack  HeadphoneJack  MicJack

Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
 sound/core/jack.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/sound/core/jack.c b/sound/core/jack.c
index 0092cb6b5b79..e1d1b26f3a5e 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -243,18 +243,36 @@ static const struct file_operations jackin_inject_fops = {
 	.llseek = default_llseek,
 };
 
+/* The substrings in the jack's name but not suitable for folder's name */
+static const char * const dropped_chars[] = {
+	"/", "=", ",", " ",
+};
+
+static char *strremove(char *s, const char *c)
+{
+	char *p;
+
+	while ((p = strstr(s, c))) {
+		*p = '\0';
+		strcat(s, p+strlen(c));
+	}
+
+	return s;
+}
+
 static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack,
 					    struct snd_jack_kctl *jack_kctl)
 {
 	char *tname;
+	int i;
 
-	/* the folder's name can't contains '/', need to replace it with '!'
-	 * as lib/kobject.c does
-	 */
 	tname = kstrdup(jack_kctl->kctl->id.name, GFP_KERNEL);
 	if (!tname)
 		return -ENOMEM;
-	strreplace(tname, '/', '!');
+
+	for (i = 0; i < ARRAY_SIZE(dropped_chars); i++)
+		tname = strremove(tname, dropped_chars[i]);
+
 	jack_kctl->jack_debugfs_root = debugfs_create_dir(tname, jack->card->debugfs_root);
 	kfree(tname);
 
-- 
2.25.1


  parent reply	other threads:[~2021-01-11 13:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 13:05 [RFC][PATCH v4 0/4] design a way to change audio Jack state by software Hui Wang
2021-01-11 13:05 ` [RFC][PATCH v4 1/4] alsa: jack: implement software jack injection via debugfs Hui Wang
2021-01-20 14:51   ` Takashi Iwai
2021-01-11 13:05 ` Hui Wang [this message]
2021-01-20 14:55   ` [RFC][PATCH v4 2/4] alsa: jack: adjust jack_kctl debugfs folder's name Takashi Iwai
2021-01-11 13:05 ` [RFC][PATCH v4 3/4] alsa: jack: add more jack_kctl debugfs nodes Hui Wang
2021-01-20 14:58   ` Takashi Iwai
2021-01-11 13:05 ` [RFC][PATCH v4 4/4] alsa: jack: implement save-and-restore for jack's hw status Hui Wang
2021-01-20  8:58 ` [RFC][PATCH v4 0/4] design a way to change audio Jack state by software Hui Wang
2021-01-20 14:47   ` Takashi Iwai
2021-01-21 12:48     ` Hui Wang

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=20210111130557.90208-3-hui.wang@canonical.com \
    --to=hui.wang@canonical.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=perex@perex.cz \
    --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;
as well as URLs for NNTP newsgroup(s).