[alsa-devel] [PATCH 3/5] ASoC: soc-core: add component /unregister_exp/remove functions

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Aug 2 06:26:27 CEST 2017


From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>

ALSA SoC platform/codec will be replaced to component soon.
This means 1 device might have multiple components. But current
unregister component function only checks "dev" to find it.
This means, unexpected component might be unregistered by current
function.
But, it is no problem if driver registered only 1 component.

To avoid this issue, this patch adds new component
unregister_exp/remove functions. This is same as "platform" style.
"unregister_exp" uses "lookup" with "dev" and "driver name".
It can find exactly correct component.

Here, the reason why it uses "driver name" is that "component name"
was created by fmt_single_name() and difficult to use it from driver.
Driver of course knows its "driver name", thus, using it is more easy.

Current normal unregister function is replaced to "unregister_exp" with
driver_name = NULL macro.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc.h  |  5 ++++-
 sound/soc/soc-core.c | 24 ++++++++++++++----------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index c777371..8428fc4 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -474,7 +474,10 @@ int snd_soc_register_component(struct device *dev,
 int devm_snd_soc_register_component(struct device *dev,
 			 const struct snd_soc_component_driver *component_driver,
 			 struct snd_soc_dai_driver *dai_drv, int num_dai);
-void snd_soc_unregister_component(struct device *dev);
+#define snd_soc_unregister_component(dev) snd_soc_unregister_component_exp(dev, NULL)
+void snd_soc_unregister_component_exp(struct device *dev,
+				      const char *driver_name);
+void snd_soc_remove_component(struct snd_soc_component *component);
 struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
 						   const char *driver_name);
 int snd_soc_cache_init(struct snd_soc_codec *codec);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index af41717..e87ba27 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3323,26 +3323,30 @@ int snd_soc_register_component(struct device *dev,
  *
  * @dev: The device to unregister
  */
-void snd_soc_unregister_component(struct device *dev)
+void snd_soc_unregister_component_exp(struct device *dev,
+				      const char *driver_name)
 {
 	struct snd_soc_component *component;
 
-	mutex_lock(&client_mutex);
-	list_for_each_entry(component, &component_list, list) {
-		if (dev == component->dev && component->registered_as_component)
-			goto found;
-	}
-	mutex_unlock(&client_mutex);
-	return;
+	component = snd_soc_lookup_component(dev, driver_name);
+	if (!component || !component->registered_as_component)
+		return;
 
-found:
+	snd_soc_remove_component(component);
+}
+EXPORT_SYMBOL_GPL(snd_soc_unregister_component_exp);
+
+void snd_soc_remove_component(struct snd_soc_component *component)
+{
+	mutex_lock(&client_mutex);
 	snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL);
 	snd_soc_component_del_unlocked(component);
 	mutex_unlock(&client_mutex);
+
 	snd_soc_component_cleanup(component);
 	kfree(component);
 }
-EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
+EXPORT_SYMBOL_GPL(snd_soc_remove_component);
 
 struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
 						   const char *driver_name)
-- 
1.9.1



More information about the Alsa-devel mailing list