Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: broonie@kernel.org, kuninori.morimoto.gx@renesas.com
Subject: [PATCH] ASoC: core: Make sure component driver names are unique
Date: Mon, 27 Apr 2020 12:33:06 -0700	[thread overview]
Message-ID: <20200427193306.31198-1-ranjani.sridharan@linux.intel.com> (raw)

When registering a component, make sure that the driver names
are unique. This will ensure that the snd_soc_rtdcom_lookup()
function returns the right component based on the name.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
 sound/soc/soc-core.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 8321e75ff244..00c1f8ce46af 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -286,14 +286,6 @@ struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
 	if (!driver_name)
 		return NULL;
 
-	/*
-	 * NOTE
-	 *
-	 * snd_soc_rtdcom_lookup() will find component from rtd by using
-	 * specified driver name.
-	 * But, if many components which have same driver name are connected
-	 * to 1 rtd, this function will return 1st found component.
-	 */
 	for_each_rtd_components(rtd, i, component) {
 		const char *component_name = component->driver->name;
 
@@ -2640,6 +2632,22 @@ int snd_soc_add_component(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(snd_soc_add_component);
 
+static bool
+snd_soc_component_driver_name_is_unique(const struct snd_soc_component_driver *component_driver)
+{
+	struct snd_soc_component *component;
+
+	mutex_lock(&client_mutex);
+	for_each_component(component)
+		if (!strcmp(component->driver->name, component_driver->name)) {
+			mutex_unlock(&client_mutex);
+			return false;
+		}
+
+	mutex_unlock(&client_mutex);
+	return true;
+}
+
 int snd_soc_register_component(struct device *dev,
 			const struct snd_soc_component_driver *component_driver,
 			struct snd_soc_dai_driver *dai_drv,
@@ -2647,6 +2655,13 @@ int snd_soc_register_component(struct device *dev,
 {
 	struct snd_soc_component *component;
 
+	if (component_driver->name &&
+	    !snd_soc_component_driver_name_is_unique(component_driver)) {
+		dev_err(dev, "component driver name %s is not unique\n",
+			component_driver->name);
+		return -EINVAL;
+	}
+
 	component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
 	if (!component)
 		return -ENOMEM;
-- 
2.17.1


             reply	other threads:[~2020-04-27 19:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 19:33 Ranjani Sridharan [this message]
2020-04-28 11:40 ` [PATCH] ASoC: core: Make sure component driver names are unique Mark Brown
2020-04-28 16:07   ` Ranjani Sridharan
2020-04-28 16:14     ` Mark Brown
2020-04-28 16:26       ` Ranjani Sridharan
2020-04-28 16:34         ` Mark Brown
2020-05-11  1:41 ` Kuninori Morimoto

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=20200427193306.31198-1-ranjani.sridharan@linux.intel.com \
    --to=ranjani.sridharan@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    /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