From: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx> 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/lookup/remove functions. "lookup" function finds component by "dev" and "driver name", and "remove" function removes it. "unregister_exp" will use these functions. 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@xxxxxxxxxxx> --- include/sound/soc.h | 7 ++++++- sound/soc/soc-core.c | 56 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index c4a8b19..82209be 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -474,7 +474,12 @@ int snd_soc_register_component(struct device *dev, int devm_snd_soc_register_component(struct device *dev, const struct snd_soc_component_driver *cmpnt_drv, 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); int snd_soc_cache_exit(struct snd_soc_codec *codec); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c240e13..0bd7764 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3323,26 +3323,56 @@ 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 *cmpnt; + struct snd_soc_component *component; + + component = snd_soc_lookup_component(dev, driver_name); + if (!component || !component->registered_as_component) + return; + 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); - list_for_each_entry(cmpnt, &component_list, list) { - if (dev == cmpnt->dev && cmpnt->registered_as_component) - goto found; - } + snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL); + snd_soc_component_del_unlocked(component); mutex_unlock(&client_mutex); - return; -found: - snd_soc_tplg_component_remove(cmpnt, SND_SOC_TPLG_INDEX_ALL); - snd_soc_component_del_unlocked(cmpnt); + snd_soc_component_cleanup(component); + kfree(component); +} +EXPORT_SYMBOL_GPL(snd_soc_remove_component); + +struct snd_soc_component *snd_soc_lookup_component(struct device *dev, + const char *driver_name) +{ + struct snd_soc_component *component; + struct snd_soc_component *ret; + + ret = NULL; + mutex_lock(&client_mutex); + list_for_each_entry(component, &component_list, list) { + if (dev != component->dev) + continue; + + if (driver_name && + (driver_name != component->driver->name) && + (strcmp(component->driver->name, driver_name) != 0)) + continue; + + ret = component; + break; + } mutex_unlock(&client_mutex); - snd_soc_component_cleanup(cmpnt); - kfree(cmpnt); + + return ret; } -EXPORT_SYMBOL_GPL(snd_soc_unregister_component); +EXPORT_SYMBOL_GPL(snd_soc_lookup_component); static int snd_soc_platform_drv_probe(struct snd_soc_component *component) { -- 1.9.1