All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jerome Brunet <jbrunet@baylibre.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC] ASoC: core: ensure component names are unique
Date: Fri, 14 Feb 2020 14:47:04 +0100	[thread overview]
Message-ID: <20200214134704.342501-1-jbrunet@baylibre.com> (raw)

Make sure each ASoC component is registered with a unique name.
The component is derived from the device name. If a device registers more
than one component, the component names will be the same.

This usually brings up a warning about the debugfs directory creation of
the component since directory already exists.

In such case, start numbering the component of the device so the names
don't collide anymore.

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---

* Here is an example of /sys/kernel/debug/asoc/components before the change:
hdmi-audio-codec.3.auto
c1105400.audio-controller
c1105400.audio-controller
c1105400.audio-controller
c8832000.audio-controller
analog-amplifier
snd-soc-dummy
snd-soc-dummy

* and after:
hdmi-audio-codec.3.auto
c1105400.audio-controller-2
c1105400.audio-controller-1
c1105400.audio-controller
c8832000.audio-controller
analog-amplifier
snd-soc-dummy-1
snd-soc-dummy

I wanted to keep the name as they were for the devices registering
only one component but we could also start the numbering from the first
component instead of the second.

 sound/soc/soc-core.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 03b87427faa7..6a58a8f6e3c4 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2446,6 +2446,33 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
 	return ret;
 }
 
+static char *snd_soc_component_unique_name(struct device *dev,
+					   struct snd_soc_component *component)
+{
+	struct snd_soc_component *pos;
+	int count = 0;
+	char *name, *unique;
+
+	name = fmt_single_name(dev, &component->id);
+	if (!name)
+		return name;
+
+	/* Count the number of components registred by the device */
+	for_each_component(pos) {
+		if (dev == pos->dev)
+			count++;
+	}
+
+	/* Keep naming as it is for the 1st component */
+	if (!count)
+		return name;
+
+	unique = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", name, count);
+	devm_kfree(dev, name);
+
+	return unique;
+}
+
 static int snd_soc_component_initialize(struct snd_soc_component *component,
 	const struct snd_soc_component_driver *driver, struct device *dev)
 {
@@ -2454,7 +2481,7 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
 	INIT_LIST_HEAD(&component->card_list);
 	mutex_init(&component->io_mutex);
 
-	component->name = fmt_single_name(dev, &component->id);
+	component->name = snd_soc_component_unique_name(dev, component);
 	if (!component->name) {
 		dev_err(dev, "ASoC: Failed to allocate name\n");
 		return -ENOMEM;
-- 
2.24.1


WARNING: multiple messages have this Message-ID (diff)
From: Jerome Brunet <jbrunet@baylibre.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	Jerome Brunet <jbrunet@baylibre.com>
Subject: [alsa-devel] [PATCH RFC] ASoC: core: ensure component names are unique
Date: Fri, 14 Feb 2020 14:47:04 +0100	[thread overview]
Message-ID: <20200214134704.342501-1-jbrunet@baylibre.com> (raw)

Make sure each ASoC component is registered with a unique name.
The component is derived from the device name. If a device registers more
than one component, the component names will be the same.

This usually brings up a warning about the debugfs directory creation of
the component since directory already exists.

In such case, start numbering the component of the device so the names
don't collide anymore.

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---

* Here is an example of /sys/kernel/debug/asoc/components before the change:
hdmi-audio-codec.3.auto
c1105400.audio-controller
c1105400.audio-controller
c1105400.audio-controller
c8832000.audio-controller
analog-amplifier
snd-soc-dummy
snd-soc-dummy

* and after:
hdmi-audio-codec.3.auto
c1105400.audio-controller-2
c1105400.audio-controller-1
c1105400.audio-controller
c8832000.audio-controller
analog-amplifier
snd-soc-dummy-1
snd-soc-dummy

I wanted to keep the name as they were for the devices registering
only one component but we could also start the numbering from the first
component instead of the second.

 sound/soc/soc-core.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 03b87427faa7..6a58a8f6e3c4 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2446,6 +2446,33 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
 	return ret;
 }
 
+static char *snd_soc_component_unique_name(struct device *dev,
+					   struct snd_soc_component *component)
+{
+	struct snd_soc_component *pos;
+	int count = 0;
+	char *name, *unique;
+
+	name = fmt_single_name(dev, &component->id);
+	if (!name)
+		return name;
+
+	/* Count the number of components registred by the device */
+	for_each_component(pos) {
+		if (dev == pos->dev)
+			count++;
+	}
+
+	/* Keep naming as it is for the 1st component */
+	if (!count)
+		return name;
+
+	unique = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", name, count);
+	devm_kfree(dev, name);
+
+	return unique;
+}
+
 static int snd_soc_component_initialize(struct snd_soc_component *component,
 	const struct snd_soc_component_driver *driver, struct device *dev)
 {
@@ -2454,7 +2481,7 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
 	INIT_LIST_HEAD(&component->card_list);
 	mutex_init(&component->io_mutex);
 
-	component->name = fmt_single_name(dev, &component->id);
+	component->name = snd_soc_component_unique_name(dev, component);
 	if (!component->name) {
 		dev_err(dev, "ASoC: Failed to allocate name\n");
 		return -ENOMEM;
-- 
2.24.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

             reply	other threads:[~2020-02-14 13:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 13:47 Jerome Brunet [this message]
2020-02-14 13:47 ` [alsa-devel] [PATCH RFC] ASoC: core: ensure component names are unique Jerome Brunet
2020-02-14 20:56 ` Applied "ASoC: core: ensure component names are unique" to the asoc tree Mark Brown
2020-02-14 20:56   ` [alsa-devel] " Mark Brown
     [not found]   ` <CGME20200217121336eucas1p2deb35417f5c4646a89762fd6146c3cf9@eucas1p2.samsung.com>
2020-02-17 12:13     ` Marek Szyprowski
2020-02-17 12:13       ` [alsa-devel] " Marek Szyprowski
2020-02-17 13:18       ` Jerome Brunet
2020-02-17 13:18         ` [alsa-devel] " Jerome Brunet
2020-02-17 14:36         ` Marek Szyprowski
2020-02-17 14:36           ` [alsa-devel] " Marek Szyprowski
2020-02-17 17:23           ` Stefan Wahren
2020-02-17 17:23             ` [alsa-devel] " Stefan Wahren
2020-02-17 18:06           ` [RFT/DONTMERGE] ASoC: devm_snd_soc_register_component fixup Jerome Brunet
2020-02-17 18:06             ` Jerome Brunet
2020-02-18  6:47             ` Marek Szyprowski
2020-02-18  6:47               ` Marek Szyprowski
2020-02-18  9:32               ` Jerome Brunet
2020-02-18  9:32                 ` Jerome Brunet
2020-02-17 13:22       ` [alsa-devel] Applied "ASoC: core: ensure component names are unique" to the asoc tree Peter Ujfalusi
2020-02-17 13:22         ` Peter Ujfalusi
2020-02-18 18:55   ` Jerome Brunet
2020-02-18 19:03     ` Mark Brown

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=20200214134704.342501-1-jbrunet@baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.