[alsa-devel] [PATCH 0/3] ASoC: soc-core: tidyup snd_soc_unregister_component()
Hi Mark
Mainly these are for platform replace to component. 1), 2) are cosmetic patch. 3) is a littile bit aggressive patch which unregister all component by 1 call.
Previous my patch-set tried to add new remove component function, but if we can unregister all component by 1 call, it is no longer needed.
Kuninori Morimoto (3): 1) ASoC: soc-core: rename "cmpnt" to "component" 2) ASoC: soc-core: remove duplicate mutex_unlock from snd_soc_unregister_component() 3) ASoC: soc-core: snd_soc_unregister_component() unregister all component
include/sound/soc.h | 4 ++-- sound/soc/soc-core.c | 60 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 26 deletions(-)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
To unify notation, to readable.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 4 ++-- sound/soc/soc-core.c | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 8f9376f..62bc0c7 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -469,10 +469,10 @@ int snd_soc_register_codec(struct device *dev, struct snd_soc_dai_driver *dai_drv, int num_dai); void snd_soc_unregister_codec(struct device *dev); int snd_soc_register_component(struct device *dev, - const struct snd_soc_component_driver *cmpnt_drv, + const struct snd_soc_component_driver *component_driver, struct snd_soc_dai_driver *dai_drv, int num_dai); int devm_snd_soc_register_component(struct device *dev, - const struct snd_soc_component_driver *cmpnt_drv, + 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); 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 13c875e..ac68be0 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3280,40 +3280,40 @@ static void snd_soc_component_del_unlocked(struct snd_soc_component *component) }
int snd_soc_register_component(struct device *dev, - const struct snd_soc_component_driver *cmpnt_drv, + const struct snd_soc_component_driver *component_driver, struct snd_soc_dai_driver *dai_drv, int num_dai) { - struct snd_soc_component *cmpnt; + struct snd_soc_component *component; int ret;
- cmpnt = kzalloc(sizeof(*cmpnt), GFP_KERNEL); - if (!cmpnt) { + component = kzalloc(sizeof(*component), GFP_KERNEL); + if (!component) { dev_err(dev, "ASoC: Failed to allocate memory\n"); return -ENOMEM; }
- ret = snd_soc_component_initialize(cmpnt, cmpnt_drv, dev); + ret = snd_soc_component_initialize(component, component_driver, dev); if (ret) goto err_free;
- cmpnt->ignore_pmdown_time = true; - cmpnt->registered_as_component = true; + component->ignore_pmdown_time = true; + component->registered_as_component = true;
- ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true); + ret = snd_soc_register_dais(component, dai_drv, num_dai, true); if (ret < 0) { dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); goto err_cleanup; }
- snd_soc_component_add(cmpnt); + snd_soc_component_add(component);
return 0;
err_cleanup: - snd_soc_component_cleanup(cmpnt); + snd_soc_component_cleanup(component); err_free: - kfree(cmpnt); + kfree(component); return ret; } EXPORT_SYMBOL_GPL(snd_soc_register_component); @@ -3325,22 +3325,22 @@ int snd_soc_register_component(struct device *dev, */ void snd_soc_unregister_component(struct device *dev) { - struct snd_soc_component *cmpnt; + 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) + list_for_each_entry(component, &component_list, list) { + if (dev == component->dev && component->registered_as_component) goto found; } 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_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL); + snd_soc_component_del_unlocked(component); mutex_unlock(&client_mutex); - snd_soc_component_cleanup(cmpnt); - kfree(cmpnt); + snd_soc_component_cleanup(component); + kfree(component); } EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current snd_soc_unregister_component() is using multiple mutex_unlock() for found/non-found cases. But it is unreadable and confusable code. This patch tidyup current code to be readable.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ac68be0..db67103 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3326,21 +3326,25 @@ int snd_soc_register_component(struct device *dev, void snd_soc_unregister_component(struct device *dev) { struct snd_soc_component *component; + int found = 0;
mutex_lock(&client_mutex); list_for_each_entry(component, &component_list, list) { - if (dev == component->dev && component->registered_as_component) - goto found; + if (dev != component->dev || + !component->registered_as_component) + continue; + + snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL); + snd_soc_component_del_unlocked(component); + found = 1; + break; } mutex_unlock(&client_mutex); - return;
-found: - 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); + if (found) { + snd_soc_component_cleanup(component); + kfree(component); + } } EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
The patch
ASoC: soc-core: remove duplicate mutex_unlock from snd_soc_unregister_component()
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 21a035287e28ec225fe7dfd1fffc509efd26a5db Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Mon, 7 Aug 2017 02:06:40 +0000 Subject: [PATCH] ASoC: soc-core: remove duplicate mutex_unlock from snd_soc_unregister_component()
Current snd_soc_unregister_component() is using multiple mutex_unlock() for found/non-found cases. But it is unreadable and confusable code. This patch tidyup current code to be readable.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index b21488972198..3bb8c63564cf 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3328,21 +3328,25 @@ EXPORT_SYMBOL_GPL(snd_soc_register_component); void snd_soc_unregister_component(struct device *dev) { struct snd_soc_component *component; + int found = 0;
mutex_lock(&client_mutex); list_for_each_entry(component, &component_list, list) { - if (dev == component->dev && component->registered_as_component) - goto found; + if (dev != component->dev || + !component->registered_as_component) + continue; + + snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL); + snd_soc_component_del_unlocked(component); + found = 1; + break; } mutex_unlock(&client_mutex); - return;
-found: - 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); + if (found) { + snd_soc_component_cleanup(component); + kfree(component); + } } EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current snd_soc_unregister_component() unregisters first found component only which was specified by dev. This style can't specify concrete component if system registered some component with same dev. And system need to call this function many times. This patch unregister all related component by 1 call.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index db67103..a407a9a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3319,11 +3319,12 @@ int snd_soc_register_component(struct device *dev, EXPORT_SYMBOL_GPL(snd_soc_register_component);
/** - * snd_soc_unregister_component - Unregister a component from the ASoC core + * snd_soc_unregister_component - Unregister all related component + * from the ASoC core * * @dev: The device to unregister */ -void snd_soc_unregister_component(struct device *dev) +static int __snd_soc_unregister_component(struct device *dev) { struct snd_soc_component *component; int found = 0; @@ -3345,6 +3346,13 @@ void snd_soc_unregister_component(struct device *dev) snd_soc_component_cleanup(component); kfree(component); } + + return found; +} + +void snd_soc_unregister_component(struct device *dev) +{ + while (__snd_soc_unregister_component(dev)); } EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
The patch
ASoC: soc-core: snd_soc_unregister_component() unregister all component
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 2eccea8cdeb8fe455fc3a45b4e097f118449c3ef Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Mon, 7 Aug 2017 02:06:55 +0000 Subject: [PATCH] ASoC: soc-core: snd_soc_unregister_component() unregister all component
Current snd_soc_unregister_component() unregisters first found component only which was specified by dev. This style can't specify concrete component if system registered some component with same dev. And system need to call this function many times. This patch unregister all related component by 1 call.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index b1860b14b075..50c8dba54649 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3365,11 +3365,12 @@ int snd_soc_register_component(struct device *dev, EXPORT_SYMBOL_GPL(snd_soc_register_component);
/** - * snd_soc_unregister_component - Unregister a component from the ASoC core + * snd_soc_unregister_component - Unregister all related component + * from the ASoC core * * @dev: The device to unregister */ -void snd_soc_unregister_component(struct device *dev) +static int __snd_soc_unregister_component(struct device *dev) { struct snd_soc_component *component; int found = 0; @@ -3391,6 +3392,13 @@ void snd_soc_unregister_component(struct device *dev) snd_soc_component_cleanup(component); kfree(component); } + + return found; +} + +void snd_soc_unregister_component(struct device *dev) +{ + while (__snd_soc_unregister_component(dev)); } EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
participants (2)
-
Kuninori Morimoto
-
Mark Brown