[alsa-devel] [PATCH 00/16] ASoC: soc-core cleanup
Hi Mark
I want to add multi CPU DAI support to ALSA SoC. But I noticed that we want to cleanup ALSA SoC before that. These patches will do nothing from "technical" point of view. Just for cleanup
Kuninori Morimoto (16): ASoC: soc-core: rename soc_post_component_init() to soc_rtd_init() ASoC: soc-core: add soc_rtd_free() ASoC: soc-core: move soc_probe_component() position ASoC: soc-core: dapm related setup at one place ASoC: soc-core: add snd_soc_dapm_init() ASoC: soc-core: move soc_probe_link_components() position ASoC: soc-core: self contained soc_probe_link_components() ASoC: soc-core: self contained soc_remove_link_components() ASoC: soc-core: self contained soc_remove_link_dais() ASoC: soc-core: move soc_probe_dai() next to soc_remove_dai() ASoC: soc-core: add new soc_link_init() ASoC: soc-core: self contained soc_probe_link_dais() ASoC: soc-core: move soc_probe_link_dais() next to soc_remove_link_dais() ASoC: soc-core: self contained soc_bind_aux_dev() ASoC: soc-core: add soc_unbind_aux_dev() ASoC: soc-core: self contained soc_unbind_aux_dev()
include/sound/soc-dapm.h | 3 + sound/soc/soc-core.c | 568 ++++++++++++++++++++++++----------------------- sound/soc/soc-dapm.c | 21 ++ 3 files changed, 310 insertions(+), 282 deletions(-)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
From function name point of view, "soc_post_component_init()" sounds like "component initialize function". But in reality it is rtd setup function.
This patch renames soc_post_component_init() to soc_rtd_init()
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0af8396..3c087b4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1340,13 +1340,12 @@ static int soc_probe_component(struct snd_soc_card *card, return ret; }
-static void rtd_release(struct device *dev) +static void soc_rtd_release(struct device *dev) { kfree(dev); }
-static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, - const char *name) +static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name) { int ret = 0;
@@ -1355,7 +1354,7 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, if (!rtd->dev) return -ENOMEM; rtd->dev->parent = rtd->card->dev; - rtd->dev->release = rtd_release; + rtd->dev->release = soc_rtd_release; rtd->dev->groups = soc_dev_attr_groups; dev_set_name(rtd->dev, "%s", name); dev_set_drvdata(rtd->dev, rtd); @@ -1483,7 +1482,7 @@ static int soc_probe_link_dais(struct snd_soc_card *card, return ret; }
- ret = soc_post_component_init(rtd, dai_link->name); + ret = soc_rtd_init(rtd, dai_link->name); if (ret) return ret;
The patch
ASoC: soc-core: rename soc_post_component_init() to soc_rtd_init()
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4
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 542694df7511977c3baa6ba855126a0cce883977 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Fri, 23 Aug 2019 09:58:32 +0900 Subject: [PATCH] ASoC: soc-core: rename soc_post_component_init() to soc_rtd_init()
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
From function name point of view, "soc_post_component_init()" sounds
like "component initialize function". But in reality it is rtd setup function.
This patch renames soc_post_component_init() to soc_rtd_init()
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Link: https://lore.kernel.org/r/87v9uo7lc3.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0af83963289f..3c087b478398 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1340,13 +1340,12 @@ static int soc_probe_component(struct snd_soc_card *card, return ret; }
-static void rtd_release(struct device *dev) +static void soc_rtd_release(struct device *dev) { kfree(dev); }
-static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, - const char *name) +static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name) { int ret = 0;
@@ -1355,7 +1354,7 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, if (!rtd->dev) return -ENOMEM; rtd->dev->parent = rtd->card->dev; - rtd->dev->release = rtd_release; + rtd->dev->release = soc_rtd_release; rtd->dev->groups = soc_dev_attr_groups; dev_set_name(rtd->dev, "%s", name); dev_set_drvdata(rtd->dev, rtd); @@ -1483,7 +1482,7 @@ static int soc_probe_link_dais(struct snd_soc_card *card, return ret; }
- ret = soc_post_component_init(rtd, dai_link->name); + ret = soc_rtd_init(rtd, dai_link->name); if (ret) return ret;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc_rtd_init() was soc_post_component_init(), but there was no its paired soc_post_component_free(), but it is done at soc_remove_link_dais(). This means it is difficult to find related code.
This patch adds soc_rtd_free() which is paired soc_rtd_init(). soc_rtd_xxx() will be more cleanuped in the future.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3c087b4..3754a08 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -975,17 +975,15 @@ static void soc_remove_dai(struct snd_soc_dai *dai, int order) dai->probed = 0; }
+static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd); /* remove me */ static void soc_remove_link_dais(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, int order) { int i; struct snd_soc_dai *codec_dai;
- /* unregister the rtd device */ - if (rtd->dev_registered) { - device_unregister(rtd->dev); - rtd->dev_registered = 0; - } + /* finalize rtd device */ + soc_rtd_free(rtd);
/* remove the CODEC DAI */ for_each_rtd_codec_dai(rtd, i, codec_dai) @@ -1340,6 +1338,15 @@ static int soc_probe_component(struct snd_soc_card *card, return ret; }
+static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd) +{ + if (rtd->dev_registered) { + /* we don't need to call kfree() for rtd->dev */ + device_unregister(rtd->dev); + rtd->dev_registered = 0; + } +} + static void soc_rtd_release(struct device *dev) { kfree(dev);
The patch
ASoC: soc-core: add soc_rtd_free()
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4
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 9a7c9fe1203eb360b3a01b65a18bcd0de6670c53 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Fri, 23 Aug 2019 09:58:37 +0900 Subject: [PATCH] ASoC: soc-core: add soc_rtd_free()
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc_rtd_init() was soc_post_component_init(), but there was no its paired soc_post_component_free(), but it is done at soc_remove_link_dais(). This means it is difficult to find related code.
This patch adds soc_rtd_free() which is paired soc_rtd_init(). soc_rtd_xxx() will be more cleanuped in the future.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Link: https://lore.kernel.org/r/87tva87lby.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3c087b478398..3754a08baf62 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -975,17 +975,15 @@ static void soc_remove_dai(struct snd_soc_dai *dai, int order) dai->probed = 0; }
+static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd); /* remove me */ static void soc_remove_link_dais(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, int order) { int i; struct snd_soc_dai *codec_dai;
- /* unregister the rtd device */ - if (rtd->dev_registered) { - device_unregister(rtd->dev); - rtd->dev_registered = 0; - } + /* finalize rtd device */ + soc_rtd_free(rtd);
/* remove the CODEC DAI */ for_each_rtd_codec_dai(rtd, i, codec_dai) @@ -1340,6 +1338,15 @@ static int soc_probe_component(struct snd_soc_card *card, return ret; }
+static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd) +{ + if (rtd->dev_registered) { + /* we don't need to call kfree() for rtd->dev */ + device_unregister(rtd->dev); + rtd->dev_registered = 0; + } +} + static void soc_rtd_release(struct device *dev) { kfree(dev);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc_probe_comonent() has paired soc_remove_comonent(), but, these are implemented at different place. So it is difficult to confirm code. This patch moves soc_probe_component() next to soc_remove_component().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 261 +++++++++++++++++++++++++-------------------------- 1 file changed, 130 insertions(+), 131 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3754a08..8fa1cfc 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -938,6 +938,41 @@ static int soc_bind_dai_link(struct snd_soc_card *card, return -EPROBE_DEFER; }
+static void soc_set_of_name_prefix(struct snd_soc_component *component) +{ + struct device_node *of_node = soc_component_to_node(component); + const char *str; + int ret; + + ret = of_property_read_string(of_node, "sound-name-prefix", &str); + if (!ret) + component->name_prefix = str; +} + +static void soc_set_name_prefix(struct snd_soc_card *card, + struct snd_soc_component *component) +{ + int i; + + for (i = 0; i < card->num_configs && card->codec_conf; i++) { + struct snd_soc_codec_conf *map = &card->codec_conf[i]; + struct device_node *of_node = soc_component_to_node(component); + + if (map->of_node && of_node != map->of_node) + continue; + if (map->dev_name && strcmp(component->name, map->dev_name)) + continue; + component->name_prefix = map->name_prefix; + return; + } + + /* + * If there is no configuration table or no match in the table, + * check if a prefix is provided in the node + */ + soc_set_of_name_prefix(component); +} + static void soc_cleanup_component(struct snd_soc_component *component) { snd_soc_component_set_jack(component, NULL, NULL); @@ -958,6 +993,101 @@ static void soc_remove_component(struct snd_soc_component *component) soc_cleanup_component(component); }
+static int soc_probe_component(struct snd_soc_card *card, + struct snd_soc_component *component) +{ + struct snd_soc_dapm_context *dapm = + snd_soc_component_get_dapm(component); + struct snd_soc_dai *dai; + int ret; + + if (!strcmp(component->name, "snd-soc-dummy")) + return 0; + + if (component->card) { + if (component->card != card) { + dev_err(component->dev, + "Trying to bind component to card "%s" but is already bound to card "%s"\n", + card->name, component->card->name); + return -ENODEV; + } + return 0; + } + + ret = snd_soc_component_module_get_when_probe(component); + if (ret < 0) + return ret; + + component->card = card; + dapm->card = card; + INIT_LIST_HEAD(&dapm->list); + soc_set_name_prefix(card, component); + + soc_init_component_debugfs(component); + + ret = snd_soc_dapm_new_controls(dapm, + component->driver->dapm_widgets, + component->driver->num_dapm_widgets); + + if (ret != 0) { + dev_err(component->dev, + "Failed to create new controls %d\n", ret); + goto err_probe; + } + + for_each_component_dais(component, dai) { + ret = snd_soc_dapm_new_dai_widgets(dapm, dai); + if (ret != 0) { + dev_err(component->dev, + "Failed to create DAI widgets %d\n", ret); + goto err_probe; + } + } + + ret = snd_soc_component_probe(component); + if (ret < 0) { + dev_err(component->dev, + "ASoC: failed to probe component %d\n", ret); + goto err_probe; + } + WARN(dapm->idle_bias_off && + dapm->bias_level != SND_SOC_BIAS_OFF, + "codec %s can not start from non-off bias with idle_bias_off==1\n", + component->name); + + /* machine specific init */ + if (component->init) { + ret = component->init(component); + if (ret < 0) { + dev_err(component->dev, + "Failed to do machine specific init %d\n", ret); + goto err_probe; + } + } + + ret = snd_soc_add_component_controls(component, + component->driver->controls, + component->driver->num_controls); + if (ret < 0) + goto err_probe; + + ret = snd_soc_dapm_add_routes(dapm, + component->driver->dapm_routes, + component->driver->num_dapm_routes); + if (ret < 0) + goto err_probe; + + list_add(&dapm->list, &card->dapm_list); + /* see for_each_card_components */ + list_add(&component->card_list, &card->component_dev_list); + +err_probe: + if (ret < 0) + soc_cleanup_component(component); + + return ret; +} + static void soc_remove_dai(struct snd_soc_dai *dai, int order) { int err; @@ -1207,137 +1337,6 @@ void snd_soc_remove_dai_link(struct snd_soc_card *card, } EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
-static void soc_set_of_name_prefix(struct snd_soc_component *component) -{ - struct device_node *component_of_node = soc_component_to_node(component); - const char *str; - int ret; - - ret = of_property_read_string(component_of_node, "sound-name-prefix", - &str); - if (!ret) - component->name_prefix = str; -} - -static void soc_set_name_prefix(struct snd_soc_card *card, - struct snd_soc_component *component) -{ - int i; - - for (i = 0; i < card->num_configs && card->codec_conf; i++) { - struct snd_soc_codec_conf *map = &card->codec_conf[i]; - struct device_node *component_of_node = soc_component_to_node(component); - - if (map->of_node && component_of_node != map->of_node) - continue; - if (map->dev_name && strcmp(component->name, map->dev_name)) - continue; - component->name_prefix = map->name_prefix; - return; - } - - /* - * If there is no configuration table or no match in the table, - * check if a prefix is provided in the node - */ - soc_set_of_name_prefix(component); -} - -static int soc_probe_component(struct snd_soc_card *card, - struct snd_soc_component *component) -{ - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - struct snd_soc_dai *dai; - int ret; - - if (!strcmp(component->name, "snd-soc-dummy")) - return 0; - - if (component->card) { - if (component->card != card) { - dev_err(component->dev, - "Trying to bind component to card "%s" but is already bound to card "%s"\n", - card->name, component->card->name); - return -ENODEV; - } - return 0; - } - - ret = snd_soc_component_module_get_when_probe(component); - if (ret < 0) - return ret; - - component->card = card; - dapm->card = card; - INIT_LIST_HEAD(&dapm->list); - soc_set_name_prefix(card, component); - - soc_init_component_debugfs(component); - - ret = snd_soc_dapm_new_controls(dapm, - component->driver->dapm_widgets, - component->driver->num_dapm_widgets); - - if (ret != 0) { - dev_err(component->dev, - "Failed to create new controls %d\n", ret); - goto err_probe; - } - - for_each_component_dais(component, dai) { - ret = snd_soc_dapm_new_dai_widgets(dapm, dai); - if (ret != 0) { - dev_err(component->dev, - "Failed to create DAI widgets %d\n", ret); - goto err_probe; - } - } - - ret = snd_soc_component_probe(component); - if (ret < 0) { - dev_err(component->dev, - "ASoC: failed to probe component %d\n", ret); - goto err_probe; - } - WARN(dapm->idle_bias_off && - dapm->bias_level != SND_SOC_BIAS_OFF, - "codec %s can not start from non-off bias with idle_bias_off==1\n", - component->name); - - /* machine specific init */ - if (component->init) { - ret = component->init(component); - if (ret < 0) { - dev_err(component->dev, - "Failed to do machine specific init %d\n", ret); - goto err_probe; - } - } - - ret = snd_soc_add_component_controls(component, - component->driver->controls, - component->driver->num_controls); - if (ret < 0) - goto err_probe; - - ret = snd_soc_dapm_add_routes(dapm, - component->driver->dapm_routes, - component->driver->num_dapm_routes); - if (ret < 0) - goto err_probe; - - list_add(&dapm->list, &card->dapm_list); - /* see for_each_card_components */ - list_add(&component->card_list, &card->component_dev_list); - -err_probe: - if (ret < 0) - soc_cleanup_component(component); - - return ret; -} - static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd) { if (rtd->dev_registered) {
The patch
ASoC: soc-core: move soc_probe_component() position
has been applied to the asoc tree at
https://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 ffd60fba19d9752f553aac367cd40362011ab6c9 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Fri, 23 Aug 2019 09:58:42 +0900 Subject: [PATCH] ASoC: soc-core: move soc_probe_component() position
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc_probe_comonent() has paired soc_remove_comonent(), but, these are implemented at different place. So it is difficult to confirm code. This patch moves soc_probe_component() next to soc_remove_component().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Link: https://lore.kernel.org/r/87sgps7lbt.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 261 +++++++++++++++++++++---------------------- 1 file changed, 130 insertions(+), 131 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3754a08baf62..8fa1cfcc6f17 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -938,6 +938,41 @@ static int soc_bind_dai_link(struct snd_soc_card *card, return -EPROBE_DEFER; }
+static void soc_set_of_name_prefix(struct snd_soc_component *component) +{ + struct device_node *of_node = soc_component_to_node(component); + const char *str; + int ret; + + ret = of_property_read_string(of_node, "sound-name-prefix", &str); + if (!ret) + component->name_prefix = str; +} + +static void soc_set_name_prefix(struct snd_soc_card *card, + struct snd_soc_component *component) +{ + int i; + + for (i = 0; i < card->num_configs && card->codec_conf; i++) { + struct snd_soc_codec_conf *map = &card->codec_conf[i]; + struct device_node *of_node = soc_component_to_node(component); + + if (map->of_node && of_node != map->of_node) + continue; + if (map->dev_name && strcmp(component->name, map->dev_name)) + continue; + component->name_prefix = map->name_prefix; + return; + } + + /* + * If there is no configuration table or no match in the table, + * check if a prefix is provided in the node + */ + soc_set_of_name_prefix(component); +} + static void soc_cleanup_component(struct snd_soc_component *component) { snd_soc_component_set_jack(component, NULL, NULL); @@ -958,6 +993,101 @@ static void soc_remove_component(struct snd_soc_component *component) soc_cleanup_component(component); }
+static int soc_probe_component(struct snd_soc_card *card, + struct snd_soc_component *component) +{ + struct snd_soc_dapm_context *dapm = + snd_soc_component_get_dapm(component); + struct snd_soc_dai *dai; + int ret; + + if (!strcmp(component->name, "snd-soc-dummy")) + return 0; + + if (component->card) { + if (component->card != card) { + dev_err(component->dev, + "Trying to bind component to card "%s" but is already bound to card "%s"\n", + card->name, component->card->name); + return -ENODEV; + } + return 0; + } + + ret = snd_soc_component_module_get_when_probe(component); + if (ret < 0) + return ret; + + component->card = card; + dapm->card = card; + INIT_LIST_HEAD(&dapm->list); + soc_set_name_prefix(card, component); + + soc_init_component_debugfs(component); + + ret = snd_soc_dapm_new_controls(dapm, + component->driver->dapm_widgets, + component->driver->num_dapm_widgets); + + if (ret != 0) { + dev_err(component->dev, + "Failed to create new controls %d\n", ret); + goto err_probe; + } + + for_each_component_dais(component, dai) { + ret = snd_soc_dapm_new_dai_widgets(dapm, dai); + if (ret != 0) { + dev_err(component->dev, + "Failed to create DAI widgets %d\n", ret); + goto err_probe; + } + } + + ret = snd_soc_component_probe(component); + if (ret < 0) { + dev_err(component->dev, + "ASoC: failed to probe component %d\n", ret); + goto err_probe; + } + WARN(dapm->idle_bias_off && + dapm->bias_level != SND_SOC_BIAS_OFF, + "codec %s can not start from non-off bias with idle_bias_off==1\n", + component->name); + + /* machine specific init */ + if (component->init) { + ret = component->init(component); + if (ret < 0) { + dev_err(component->dev, + "Failed to do machine specific init %d\n", ret); + goto err_probe; + } + } + + ret = snd_soc_add_component_controls(component, + component->driver->controls, + component->driver->num_controls); + if (ret < 0) + goto err_probe; + + ret = snd_soc_dapm_add_routes(dapm, + component->driver->dapm_routes, + component->driver->num_dapm_routes); + if (ret < 0) + goto err_probe; + + list_add(&dapm->list, &card->dapm_list); + /* see for_each_card_components */ + list_add(&component->card_list, &card->component_dev_list); + +err_probe: + if (ret < 0) + soc_cleanup_component(component); + + return ret; +} + static void soc_remove_dai(struct snd_soc_dai *dai, int order) { int err; @@ -1207,137 +1337,6 @@ void snd_soc_remove_dai_link(struct snd_soc_card *card, } EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
-static void soc_set_of_name_prefix(struct snd_soc_component *component) -{ - struct device_node *component_of_node = soc_component_to_node(component); - const char *str; - int ret; - - ret = of_property_read_string(component_of_node, "sound-name-prefix", - &str); - if (!ret) - component->name_prefix = str; -} - -static void soc_set_name_prefix(struct snd_soc_card *card, - struct snd_soc_component *component) -{ - int i; - - for (i = 0; i < card->num_configs && card->codec_conf; i++) { - struct snd_soc_codec_conf *map = &card->codec_conf[i]; - struct device_node *component_of_node = soc_component_to_node(component); - - if (map->of_node && component_of_node != map->of_node) - continue; - if (map->dev_name && strcmp(component->name, map->dev_name)) - continue; - component->name_prefix = map->name_prefix; - return; - } - - /* - * If there is no configuration table or no match in the table, - * check if a prefix is provided in the node - */ - soc_set_of_name_prefix(component); -} - -static int soc_probe_component(struct snd_soc_card *card, - struct snd_soc_component *component) -{ - struct snd_soc_dapm_context *dapm = - snd_soc_component_get_dapm(component); - struct snd_soc_dai *dai; - int ret; - - if (!strcmp(component->name, "snd-soc-dummy")) - return 0; - - if (component->card) { - if (component->card != card) { - dev_err(component->dev, - "Trying to bind component to card "%s" but is already bound to card "%s"\n", - card->name, component->card->name); - return -ENODEV; - } - return 0; - } - - ret = snd_soc_component_module_get_when_probe(component); - if (ret < 0) - return ret; - - component->card = card; - dapm->card = card; - INIT_LIST_HEAD(&dapm->list); - soc_set_name_prefix(card, component); - - soc_init_component_debugfs(component); - - ret = snd_soc_dapm_new_controls(dapm, - component->driver->dapm_widgets, - component->driver->num_dapm_widgets); - - if (ret != 0) { - dev_err(component->dev, - "Failed to create new controls %d\n", ret); - goto err_probe; - } - - for_each_component_dais(component, dai) { - ret = snd_soc_dapm_new_dai_widgets(dapm, dai); - if (ret != 0) { - dev_err(component->dev, - "Failed to create DAI widgets %d\n", ret); - goto err_probe; - } - } - - ret = snd_soc_component_probe(component); - if (ret < 0) { - dev_err(component->dev, - "ASoC: failed to probe component %d\n", ret); - goto err_probe; - } - WARN(dapm->idle_bias_off && - dapm->bias_level != SND_SOC_BIAS_OFF, - "codec %s can not start from non-off bias with idle_bias_off==1\n", - component->name); - - /* machine specific init */ - if (component->init) { - ret = component->init(component); - if (ret < 0) { - dev_err(component->dev, - "Failed to do machine specific init %d\n", ret); - goto err_probe; - } - } - - ret = snd_soc_add_component_controls(component, - component->driver->controls, - component->driver->num_controls); - if (ret < 0) - goto err_probe; - - ret = snd_soc_dapm_add_routes(dapm, - component->driver->dapm_routes, - component->driver->num_dapm_routes); - if (ret < 0) - goto err_probe; - - list_add(&dapm->list, &card->dapm_list); - /* see for_each_card_components */ - list_add(&component->card_list, &card->component_dev_list); - -err_probe: - if (ret < 0) - soc_cleanup_component(component); - - return ret; -} - static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd) { if (rtd->dev_registered) {
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current ASoC setups some dapm related member at snd_soc_component_initialize() which is called when component was registered, and setups remaining member at soc_probe_component() which is called when component was probed. This kind of setup separation is no meanings, and it is very difficult to read and confusable. This patch setups all dapm settings at one place.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 8fa1cfc..21c005a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1019,12 +1019,19 @@ static int soc_probe_component(struct snd_soc_card *card, return ret;
component->card = card; - dapm->card = card; - INIT_LIST_HEAD(&dapm->list); soc_set_name_prefix(card, component);
soc_init_component_debugfs(component);
+ INIT_LIST_HEAD(&dapm->list); + dapm->card = card; + dapm->dev = component->dev; + dapm->component = component; + dapm->bias_level = SND_SOC_BIAS_OFF; + dapm->idle_bias_off = !component->driver->idle_bias_on; + dapm->suspend_bias_off = component->driver->suspend_bias_off; + list_add(&dapm->list, &card->dapm_list); + ret = snd_soc_dapm_new_controls(dapm, component->driver->dapm_widgets, component->driver->num_dapm_widgets); @@ -1077,7 +1084,6 @@ static int soc_probe_component(struct snd_soc_card *card, if (ret < 0) goto err_probe;
- list_add(&dapm->list, &card->dapm_list); /* see for_each_card_components */ list_add(&component->card_list, &card->component_dev_list);
@@ -2649,8 +2655,6 @@ EXPORT_SYMBOL_GPL(snd_soc_register_dai); static int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev) { - struct snd_soc_dapm_context *dapm; - INIT_LIST_HEAD(&component->dai_list); INIT_LIST_HEAD(&component->dobj_list); INIT_LIST_HEAD(&component->card_list); @@ -2665,13 +2669,6 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, component->dev = dev; component->driver = driver;
- dapm = snd_soc_component_get_dapm(component); - dapm->dev = dev; - dapm->component = component; - dapm->bias_level = SND_SOC_BIAS_OFF; - dapm->idle_bias_off = !driver->idle_bias_on; - dapm->suspend_bias_off = driver->suspend_bias_off; - return 0; }
The patch
ASoC: soc-core: dapm related setup at one place
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4
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 b614beafa495c7f6fbc15cb6977e3fe48beea1e5 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Fri, 23 Aug 2019 09:58:47 +0900 Subject: [PATCH] ASoC: soc-core: dapm related setup at one place
Current ASoC setups some dapm related member at snd_soc_component_initialize() which is called when component was registered, and setups remaining member at soc_probe_component() which is called when component was probed. This kind of setup separation is no meanings, and it is very difficult to read and confusable. This patch setups all dapm settings at one place.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Link: https://lore.kernel.org/r/87r25c7lbo.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 8fa1cfcc6f17..21c005a044e8 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1019,12 +1019,19 @@ static int soc_probe_component(struct snd_soc_card *card, return ret;
component->card = card; - dapm->card = card; - INIT_LIST_HEAD(&dapm->list); soc_set_name_prefix(card, component);
soc_init_component_debugfs(component);
+ INIT_LIST_HEAD(&dapm->list); + dapm->card = card; + dapm->dev = component->dev; + dapm->component = component; + dapm->bias_level = SND_SOC_BIAS_OFF; + dapm->idle_bias_off = !component->driver->idle_bias_on; + dapm->suspend_bias_off = component->driver->suspend_bias_off; + list_add(&dapm->list, &card->dapm_list); + ret = snd_soc_dapm_new_controls(dapm, component->driver->dapm_widgets, component->driver->num_dapm_widgets); @@ -1077,7 +1084,6 @@ static int soc_probe_component(struct snd_soc_card *card, if (ret < 0) goto err_probe;
- list_add(&dapm->list, &card->dapm_list); /* see for_each_card_components */ list_add(&component->card_list, &card->component_dev_list);
@@ -2649,8 +2655,6 @@ EXPORT_SYMBOL_GPL(snd_soc_register_dai); static int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev) { - struct snd_soc_dapm_context *dapm; - INIT_LIST_HEAD(&component->dai_list); INIT_LIST_HEAD(&component->dobj_list); INIT_LIST_HEAD(&component->card_list); @@ -2665,13 +2669,6 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, component->dev = dev; component->driver = driver;
- dapm = snd_soc_component_get_dapm(component); - dapm->dev = dev; - dapm->component = component; - dapm->bias_level = SND_SOC_BIAS_OFF; - dapm->idle_bias_off = !driver->idle_bias_on; - dapm->suspend_bias_off = driver->suspend_bias_off; - return 0; }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc-dapm has snd_soc_dapm_free() which cleanups debugfs, widgets, list. But, there is no paired initialize function. This patch adds snd_soc_dapm_init() and initilaizing dapm
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc-dapm.h | 3 +++ sound/soc/soc-core.c | 14 ++------------ sound/soc/soc-dapm.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 2aa73d6..dd993dd 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -416,6 +416,9 @@ int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream, /* dapm path setup */ int snd_soc_dapm_new_widgets(struct snd_soc_card *card); void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm); +void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm, + struct snd_soc_card *card, + struct snd_soc_component *component); int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, const struct snd_soc_dapm_route *route, int num); int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 21c005a..8e831ae 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1023,14 +1023,7 @@ static int soc_probe_component(struct snd_soc_card *card,
soc_init_component_debugfs(component);
- INIT_LIST_HEAD(&dapm->list); - dapm->card = card; - dapm->dev = component->dev; - dapm->component = component; - dapm->bias_level = SND_SOC_BIAS_OFF; - dapm->idle_bias_off = !component->driver->idle_bias_on; - dapm->suspend_bias_off = component->driver->suspend_bias_off; - list_add(&dapm->list, &card->dapm_list); + snd_soc_dapm_init(dapm, card, component);
ret = snd_soc_dapm_new_controls(dapm, component->driver->dapm_widgets, @@ -1937,10 +1930,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) } mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
- card->dapm.bias_level = SND_SOC_BIAS_OFF; - card->dapm.dev = card->dev; - card->dapm.card = card; - list_add(&card->dapm.list, &card->dapm_list); + snd_soc_dapm_init(&card->dapm, card, NULL);
/* check whether any platform is ignore machine FE and using topology */ soc_check_tplg_fes(card); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 10819b3..b6378f0 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -4717,6 +4717,27 @@ void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) } EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
+void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm, + struct snd_soc_card *card, + struct snd_soc_component *component) +{ + dapm->card = card; + dapm->component = component; + dapm->bias_level = SND_SOC_BIAS_OFF; + + if (component) { + dapm->dev = component->dev; + dapm->idle_bias_off = !component->driver->idle_bias_on, + dapm->suspend_bias_off = component->driver->suspend_bias_off; + } else { + dapm->dev = card->dev; + } + + INIT_LIST_HEAD(&dapm->list); + list_add(&dapm->list, &card->dapm_list); +} +EXPORT_SYMBOL_GPL(snd_soc_dapm_init); + static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm) { struct snd_soc_card *card = dapm->card;
The patch
ASoC: soc-core: add snd_soc_dapm_init()
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4
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 95c267dd20431f0eb54ca204bd73a7d85c532a37 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Fri, 23 Aug 2019 09:58:52 +0900 Subject: [PATCH] ASoC: soc-core: add snd_soc_dapm_init()
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc-dapm has snd_soc_dapm_free() which cleanups debugfs, widgets, list. But, there is no paired initialize function. This patch adds snd_soc_dapm_init() and initilaizing dapm
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Link: https://lore.kernel.org/r/87pnkw7lbj.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- include/sound/soc-dapm.h | 3 +++ sound/soc/soc-core.c | 14 ++------------ sound/soc/soc-dapm.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 2aa73d6dd7be..dd993dd29229 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -416,6 +416,9 @@ int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream, /* dapm path setup */ int snd_soc_dapm_new_widgets(struct snd_soc_card *card); void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm); +void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm, + struct snd_soc_card *card, + struct snd_soc_component *component); int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, const struct snd_soc_dapm_route *route, int num); int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 21c005a044e8..8e831ae59eb8 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1023,14 +1023,7 @@ static int soc_probe_component(struct snd_soc_card *card,
soc_init_component_debugfs(component);
- INIT_LIST_HEAD(&dapm->list); - dapm->card = card; - dapm->dev = component->dev; - dapm->component = component; - dapm->bias_level = SND_SOC_BIAS_OFF; - dapm->idle_bias_off = !component->driver->idle_bias_on; - dapm->suspend_bias_off = component->driver->suspend_bias_off; - list_add(&dapm->list, &card->dapm_list); + snd_soc_dapm_init(dapm, card, component);
ret = snd_soc_dapm_new_controls(dapm, component->driver->dapm_widgets, @@ -1937,10 +1930,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) } mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
- card->dapm.bias_level = SND_SOC_BIAS_OFF; - card->dapm.dev = card->dev; - card->dapm.card = card; - list_add(&card->dapm.list, &card->dapm_list); + snd_soc_dapm_init(&card->dapm, card, NULL);
/* check whether any platform is ignore machine FE and using topology */ soc_check_tplg_fes(card); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 10819b3e0b98..b6378f025836 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -4717,6 +4717,27 @@ void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) } EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
+void snd_soc_dapm_init(struct snd_soc_dapm_context *dapm, + struct snd_soc_card *card, + struct snd_soc_component *component) +{ + dapm->card = card; + dapm->component = component; + dapm->bias_level = SND_SOC_BIAS_OFF; + + if (component) { + dapm->dev = component->dev; + dapm->idle_bias_off = !component->driver->idle_bias_on, + dapm->suspend_bias_off = component->driver->suspend_bias_off; + } else { + dapm->dev = card->dev; + } + + INIT_LIST_HEAD(&dapm->list); + list_add(&dapm->list, &card->dapm_list); +} +EXPORT_SYMBOL_GPL(snd_soc_dapm_init); + static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm) { struct snd_soc_card *card = dapm->card;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc_probe_link_components() has paired soc_remove_link_components(), but, these are implemented at different place. So it is difficult to confirm code. This patch moves soc_probe_link_components() next to soc_remove_link_components().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 8e831ae..2a166ab 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1135,6 +1135,26 @@ static void soc_remove_link_components(struct snd_soc_card *card, } }
+static int soc_probe_link_components(struct snd_soc_card *card, + struct snd_soc_pcm_runtime *rtd, int order) +{ + struct snd_soc_component *component; + struct snd_soc_rtdcom_list *rtdcom; + int ret; + + for_each_rtdcom(rtd, rtdcom) { + component = rtdcom->component; + + if (component->driver->probe_order == order) { + ret = soc_probe_component(card, component); + if (ret < 0) + return ret; + } + } + + return 0; +} + static void soc_remove_dai_links(struct snd_soc_card *card) { int order; @@ -1379,26 +1399,6 @@ static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name) return 0; }
-static int soc_probe_link_components(struct snd_soc_card *card, - struct snd_soc_pcm_runtime *rtd, int order) -{ - struct snd_soc_component *component; - struct snd_soc_rtdcom_list *rtdcom; - int ret; - - for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; - - if (component->driver->probe_order == order) { - ret = soc_probe_component(card, component); - if (ret < 0) - return ret; - } - } - - return 0; -} - static int soc_probe_dai(struct snd_soc_dai *dai, int order) { int ret;
The patch
ASoC: soc-core: move soc_probe_link_components() position
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4
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 6fb035502956ad1f338ca61c057653d5372ffd8c Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Date: Fri, 23 Aug 2019 09:58:58 +0900 Subject: [PATCH] ASoC: soc-core: move soc_probe_link_components() position
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc_probe_link_components() has paired soc_remove_link_components(), but, these are implemented at different place. So it is difficult to confirm code. This patch moves soc_probe_link_components() next to soc_remove_link_components().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com Link: https://lore.kernel.org/r/87o90g7lbd.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/soc-core.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 8e831ae59eb8..2a166abaade1 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1135,6 +1135,26 @@ static void soc_remove_link_components(struct snd_soc_card *card, } }
+static int soc_probe_link_components(struct snd_soc_card *card, + struct snd_soc_pcm_runtime *rtd, int order) +{ + struct snd_soc_component *component; + struct snd_soc_rtdcom_list *rtdcom; + int ret; + + for_each_rtdcom(rtd, rtdcom) { + component = rtdcom->component; + + if (component->driver->probe_order == order) { + ret = soc_probe_component(card, component); + if (ret < 0) + return ret; + } + } + + return 0; +} + static void soc_remove_dai_links(struct snd_soc_card *card) { int order; @@ -1379,26 +1399,6 @@ static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name) return 0; }
-static int soc_probe_link_components(struct snd_soc_card *card, - struct snd_soc_pcm_runtime *rtd, int order) -{ - struct snd_soc_component *component; - struct snd_soc_rtdcom_list *rtdcom; - int ret; - - for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; - - if (component->driver->probe_order == order) { - ret = soc_probe_component(card, component); - if (ret < 0) - return ret; - } - } - - return 0; -} - static int soc_probe_dai(struct snd_soc_dai *dai, int order) { int ret;
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_probe_link_components() implementation is very half, thus it is very difficult to read.
for_each_comp_order(xxx) { for_each_card_rtds(xxx) { => ret = soc_probe_link_components(xxx); ... } }
This patch does all for_each_xxx() under soc_probe_link_components(), and makes it to self contained.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2a166ab..e3bda9e 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1135,20 +1135,25 @@ static void soc_remove_link_components(struct snd_soc_card *card, } }
-static int soc_probe_link_components(struct snd_soc_card *card, - struct snd_soc_pcm_runtime *rtd, int order) +static int soc_probe_link_components(struct snd_soc_card *card) { struct snd_soc_component *component; + struct snd_soc_pcm_runtime *rtd; struct snd_soc_rtdcom_list *rtdcom; - int ret; + int ret, order;
- for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; + for_each_comp_order(order) { + for_each_card_rtds(card, rtd) { + for_each_rtdcom(rtd, rtdcom) { + component = rtdcom->component;
- if (component->driver->probe_order == order) { - ret = soc_probe_component(card, component); - if (ret < 0) - return ret; + if (component->driver->probe_order != order) + continue; + + ret = soc_probe_component(card, component); + if (ret < 0) + return ret; + } } }
@@ -1988,16 +1993,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) }
/* probe all components used by DAI links on this card */ - for_each_comp_order(order) { - for_each_card_rtds(card, rtd) { - ret = soc_probe_link_components(card, rtd, order); - if (ret < 0) { - dev_err(card->dev, - "ASoC: failed to instantiate card %d\n", - ret); - goto probe_end; - } - } + ret = soc_probe_link_components(card); + if (ret < 0) { + dev_err(card->dev, + "ASoC: failed to instantiate card %d\n", ret); + goto probe_end; }
/* probe auxiliary components */
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_remove_link_components() implementation is very half, thus it is very difficult to read.
for_each_comp_order(xxx) { for_each_card_rtds(xxx) => soc_remove_link_components(xxx); }
This patch does all for_each_xxx() under soc_remove_link_components(), and makes it to self contained.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e3bda9e..e2708e0 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1121,17 +1121,24 @@ static void soc_remove_link_dais(struct snd_soc_card *card, soc_remove_dai(rtd->cpu_dai, order); }
-static void soc_remove_link_components(struct snd_soc_card *card, - struct snd_soc_pcm_runtime *rtd, int order) +static void soc_remove_link_components(struct snd_soc_card *card) { struct snd_soc_component *component; + struct snd_soc_pcm_runtime *rtd; struct snd_soc_rtdcom_list *rtdcom; + int order;
- for_each_rtdcom(rtd, rtdcom) { - component = rtdcom->component; + for_each_comp_order(order) { + for_each_card_rtds(card, rtd) { + for_each_rtdcom(rtd, rtdcom) { + component = rtdcom->component; + + if (component->driver->remove_order != order) + continue;
- if (component->driver->remove_order == order) - soc_remove_component(component); + soc_remove_component(component); + } + } } }
@@ -1171,10 +1178,7 @@ static void soc_remove_dai_links(struct snd_soc_card *card) soc_remove_link_dais(card, rtd, order); }
- for_each_comp_order(order) { - for_each_card_rtds(card, rtd) - soc_remove_link_components(card, rtd, order); - } + soc_remove_link_components(card);
for_each_card_links_safe(card, link, _link) { if (link->dobj.type == SND_SOC_DOBJ_DAI_LINK) @@ -2392,20 +2396,13 @@ EXPORT_SYMBOL_GPL(snd_soc_register_card);
static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister) { - struct snd_soc_pcm_runtime *rtd; - int order; - if (card->instantiated) { card->instantiated = false; snd_soc_dapm_shutdown(card); snd_soc_flush_all_delayed_work(card);
/* remove all components used by DAI links on this card */ - for_each_comp_order(order) { - for_each_card_rtds(card, rtd) { - soc_remove_link_components(card, rtd, order); - } - } + soc_remove_link_components(card);
soc_cleanup_card_resources(card); if (!unregister)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_remove_link_dais() implementation is very half, thus it is very difficult to read.
for_each_comp_order(xxx) { for_each_card_rtds(xxx) => soc_remove_link_dais(xxx); }
This patch does all for_each_xxx() under soc_remove_link_dais(), and makes it to self contained.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e2708e0..c4581ba 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1105,20 +1105,26 @@ static void soc_remove_dai(struct snd_soc_dai *dai, int order) }
static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd); /* remove me */ -static void soc_remove_link_dais(struct snd_soc_card *card, - struct snd_soc_pcm_runtime *rtd, int order) +static void soc_remove_link_dais(struct snd_soc_card *card) { int i; struct snd_soc_dai *codec_dai; + struct snd_soc_pcm_runtime *rtd; + int order; + + for_each_comp_order(order) { + for_each_card_rtds(card, rtd) {
- /* finalize rtd device */ - soc_rtd_free(rtd); + /* finalize rtd device */ + soc_rtd_free(rtd);
- /* remove the CODEC DAI */ - for_each_rtd_codec_dai(rtd, i, codec_dai) - soc_remove_dai(codec_dai, order); + /* remove the CODEC DAI */ + for_each_rtd_codec_dai(rtd, i, codec_dai) + soc_remove_dai(codec_dai, order);
- soc_remove_dai(rtd->cpu_dai, order); + soc_remove_dai(rtd->cpu_dai, order); + } + } }
static void soc_remove_link_components(struct snd_soc_card *card) @@ -1169,14 +1175,9 @@ static int soc_probe_link_components(struct snd_soc_card *card)
static void soc_remove_dai_links(struct snd_soc_card *card) { - int order; - struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai_link *link, *_link;
- for_each_comp_order(order) { - for_each_card_rtds(card, rtd) - soc_remove_link_dais(card, rtd, order); - } + soc_remove_link_dais(card);
soc_remove_link_components(card);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
This patch moves soc_probe_dai() next to soc_remove_dai() which is paired function.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c4581ba..ab0e4ba 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1104,6 +1104,26 @@ static void soc_remove_dai(struct snd_soc_dai *dai, int order) dai->probed = 0; }
+static int soc_probe_dai(struct snd_soc_dai *dai, int order) +{ + int ret; + + if (dai->probed || + dai->driver->probe_order != order) + return 0; + + ret = snd_soc_dai_probe(dai); + if (ret < 0) { + dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n", + dai->name, ret); + return ret; + } + + dai->probed = 1; + + return 0; +} + static void soc_rtd_free(struct snd_soc_pcm_runtime *rtd); /* remove me */ static void soc_remove_link_dais(struct snd_soc_card *card) { @@ -1409,26 +1429,6 @@ static int soc_rtd_init(struct snd_soc_pcm_runtime *rtd, const char *name) return 0; }
-static int soc_probe_dai(struct snd_soc_dai *dai, int order) -{ - int ret; - - if (dai->probed || - dai->driver->probe_order != order) - return 0; - - ret = snd_soc_dai_probe(dai); - if (ret < 0) { - dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n", - dai->name, ret); - return ret; - } - - dai->probed = 1; - - return 0; -} - static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais, struct snd_soc_pcm_runtime *rtd) {
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_probe_link_dais() (1) is called under probe_order (2), and it will initialize dai_link related settings at *Last* turn (3)(B). It is very complex code.
static int soc_probe_link_dais(..., order) { (A) /* probe DAIs here */ ...
(3) if (order != SND_SOC_COMP_ORDER_LAST) return 0;
(B) /* initialize dai_link related settings */ ... }
static int snd_soc_instantiate_card(...) { ... (2) for_each_comp_order(order) { for_each_card_rtds(...) { (1) ret = soc_probe_link_dais(..., order); } } }
This patch separes soc_probe_link_dais() into "DAI probe" portion (A), and dai_link settings portion (B). The later is named as soc_link_init() by this patch.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ab0e4ba..ca06e0e 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1453,19 +1453,13 @@ static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais, static int soc_probe_link_dais(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, int order) { - struct snd_soc_dai_link *dai_link = rtd->dai_link; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_component *component; struct snd_soc_dai *codec_dai; - int i, ret, num; + int i, ret;
dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", card->name, rtd->num, order);
- /* set default power off timeout */ - rtd->pmdown_time = pmdown_time; - ret = soc_probe_dai(cpu_dai, order); if (ret) return ret; @@ -1477,9 +1471,20 @@ static int soc_probe_link_dais(struct snd_soc_card *card, return ret; }
- /* complete DAI probe during last probe */ - if (order != SND_SOC_COMP_ORDER_LAST) - return 0; + return 0; +} + +static int soc_link_init(struct snd_soc_card *card, + struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_dai_link *dai_link = rtd->dai_link; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_rtdcom_list *rtdcom; + struct snd_soc_component *component; + int ret, num; + + /* set default power off timeout */ + rtd->pmdown_time = pmdown_time;
/* do machine specific initialization */ if (dai_link->init) { @@ -2039,6 +2044,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) } }
+ for_each_card_rtds(card, rtd) + soc_link_init(card, rtd); + snd_soc_dapm_link_dai_widgets(card); snd_soc_dapm_connect_dai_link_widgets(card);
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_probe_link_dais() implementation is very half, thus it is very difficult to read.
for_each_comp_order(xxx) { for_each_card_rtds(xxx) => soc_probe_link_dais(xxx); }
This patch does all for_each_xxx() under soc_probe_link_dais(), and makes it to self contained.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ca06e0e..e6e9dad 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1450,25 +1450,30 @@ static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais, return 0; }
-static int soc_probe_link_dais(struct snd_soc_card *card, - struct snd_soc_pcm_runtime *rtd, int order) +static int soc_probe_link_dais(struct snd_soc_card *card) { - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *codec_dai; - int i, ret; + struct snd_soc_pcm_runtime *rtd; + int i, order, ret;
- dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", - card->name, rtd->num, order); + for_each_comp_order(order) { + for_each_card_rtds(card, rtd) {
- ret = soc_probe_dai(cpu_dai, order); - if (ret) - return ret; + dev_dbg(card->dev, + "ASoC: probe %s dai link %d late %d\n", + card->name, rtd->num, order);
- /* probe the CODEC DAI */ - for_each_rtd_codec_dai(rtd, i, codec_dai) { - ret = soc_probe_dai(codec_dai, order); - if (ret) - return ret; + ret = soc_probe_dai(rtd->cpu_dai, order); + if (ret) + return ret; + + /* probe the CODEC DAI */ + for_each_rtd_codec_dai(rtd, i, codec_dai) { + ret = soc_probe_dai(codec_dai, order); + if (ret) + return ret; + } + } }
return 0; @@ -1931,7 +1936,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai_link *dai_link; struct snd_soc_aux_dev *aux; - int ret, i, order; + int ret, i;
mutex_lock(&client_mutex); for_each_card_prelinks(card, i, dai_link) { @@ -2032,16 +2037,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) }
/* probe all DAI links on this card */ - for_each_comp_order(order) { - for_each_card_rtds(card, rtd) { - ret = soc_probe_link_dais(card, rtd, order); - if (ret < 0) { - dev_err(card->dev, - "ASoC: failed to instantiate card %d\n", - ret); - goto probe_end; - } - } + ret = soc_probe_link_dais(card); + if (ret < 0) { + dev_err(card->dev, + "ASoC: failed to instantiate card %d\n", ret); + goto probe_end; }
for_each_card_rtds(card, rtd)
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
This patch moves soc_probe_link_dais() next to soc_remove_link_dais() which is paired function.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e6e9dad..6b0bf3f 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1147,6 +1147,35 @@ static void soc_remove_link_dais(struct snd_soc_card *card) } }
+static int soc_probe_link_dais(struct snd_soc_card *card) +{ + struct snd_soc_dai *codec_dai; + struct snd_soc_pcm_runtime *rtd; + int i, order, ret; + + for_each_comp_order(order) { + for_each_card_rtds(card, rtd) { + + dev_dbg(card->dev, + "ASoC: probe %s dai link %d late %d\n", + card->name, rtd->num, order); + + ret = soc_probe_dai(rtd->cpu_dai, order); + if (ret) + return ret; + + /* probe the CODEC DAI */ + for_each_rtd_codec_dai(rtd, i, codec_dai) { + ret = soc_probe_dai(codec_dai, order); + if (ret) + return ret; + } + } + } + + return 0; +} + static void soc_remove_link_components(struct snd_soc_card *card) { struct snd_soc_component *component; @@ -1450,35 +1479,6 @@ static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais, return 0; }
-static int soc_probe_link_dais(struct snd_soc_card *card) -{ - struct snd_soc_dai *codec_dai; - struct snd_soc_pcm_runtime *rtd; - int i, order, ret; - - for_each_comp_order(order) { - for_each_card_rtds(card, rtd) { - - dev_dbg(card->dev, - "ASoC: probe %s dai link %d late %d\n", - card->name, rtd->num, order); - - ret = soc_probe_dai(rtd->cpu_dai, order); - if (ret) - return ret; - - /* probe the CODEC DAI */ - for_each_rtd_codec_dai(rtd, i, codec_dai) { - ret = soc_probe_dai(codec_dai, order); - if (ret) - return ret; - } - } - } - - return 0; -} - static int soc_link_init(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd) {
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_bind_aux_dev() implementation is very half, thus it is very unreadable.
for_each_card_pre_auxs(xxx) { => ret = soc_bind_aux_dev(xxx); ... }
This patch does all for_each_xxx() under soc_bind_aux_dev(), and makes it to self contained.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 6b0bf3f..1e35e85 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1557,20 +1557,22 @@ static int soc_link_init(struct snd_soc_card *card, return ret; }
-static int soc_bind_aux_dev(struct snd_soc_card *card, - struct snd_soc_aux_dev *aux_dev) +static int soc_bind_aux_dev(struct snd_soc_card *card) { struct snd_soc_component *component; + struct snd_soc_aux_dev *aux; + int i;
- /* codecs, usually analog devices */ - component = soc_find_component(&aux_dev->dlc); - if (!component) - return -EPROBE_DEFER; - - component->init = aux_dev->init; - /* see for_each_card_auxs */ - list_add(&component->card_aux_list, &card->aux_comp_list); + for_each_card_pre_auxs(card, i, aux) { + /* codecs, usually analog devices */ + component = soc_find_component(&aux->dlc); + if (!component) + return -EPROBE_DEFER;
+ component->init = aux->init; + /* see for_each_card_auxs */ + list_add(&component->card_aux_list, &card->aux_comp_list); + } return 0; }
@@ -1935,7 +1937,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) { struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai_link *dai_link; - struct snd_soc_aux_dev *aux; int ret, i;
mutex_lock(&client_mutex); @@ -1963,11 +1964,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) }
/* bind aux_devs too */ - for_each_card_pre_auxs(card, i, aux) { - ret = soc_bind_aux_dev(card, aux); - if (ret != 0) - goto probe_end; - } + ret = soc_bind_aux_dev(card); + if (ret < 0) + goto probe_end;
/* add predefined DAI links to the list */ for_each_card_prelinks(card, i, dai_link) {
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It is easy to read code if it is cleanly using paired function/naming, like start <-> stop, register <-> unregister, etc, etc. But, current ALSA SoC code is very random, unbalance, not paired, etc. It is easy to create bug at the such code, and it will be difficult to debug.
soc-core.c has soc_bind_aux_dev(), but, there is no its paired soc_unbind_aux_dev(). This patch adds soc_unbind_aux_dev().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 1e35e85..871c133 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1557,6 +1557,12 @@ static int soc_link_init(struct snd_soc_card *card, return ret; }
+static void soc_unbind_aux_dev(struct snd_soc_component *component) +{ + component->init = NULL; + list_del(&component->card_aux_list); +} + static int soc_bind_aux_dev(struct snd_soc_card *card) { struct snd_soc_component *component; @@ -1610,7 +1616,7 @@ static void soc_remove_aux_devices(struct snd_soc_card *card) if (comp->driver->remove_order == order) { soc_remove_component(comp); /* remove it from the card's aux_comp_list */ - list_del(&comp->card_aux_list); + soc_unbind_aux_dev(comp); } } }
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current soc_unbind_aux_dev() implementation is very half, thus it is very unreadable.
for_each_comp_order(order) { for_each_card_auxs_safe(card, comp, _comp) {
(1) if (comp->driver->remove_order == order) { ... => soc_unbind_aux_dev(comp); } }
soc_unbind_aux_dev() itself is not related to remove_order (1). And, it is called from soc_remove_aux_devices(), even though its paired function soc_bind_aux_dev() is called from snd_soc_instantiate_card(). It is very unbalance, and very difficult to understand.
This patch do 1) update soc_bind_aux_dev() to self contained 2) call it from soc_cleanup_card_resources() to make up balance
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 871c133..61669b9 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1557,10 +1557,14 @@ static int soc_link_init(struct snd_soc_card *card, return ret; }
-static void soc_unbind_aux_dev(struct snd_soc_component *component) +static void soc_unbind_aux_dev(struct snd_soc_card *card) { - component->init = NULL; - list_del(&component->card_aux_list); + struct snd_soc_component *component, *_component; + + for_each_card_auxs_safe(card, component, _component) { + component->init = NULL; + list_del(&component->card_aux_list); + } }
static int soc_bind_aux_dev(struct snd_soc_card *card) @@ -1612,12 +1616,8 @@ static void soc_remove_aux_devices(struct snd_soc_card *card)
for_each_comp_order(order) { for_each_card_auxs_safe(card, comp, _comp) { - - if (comp->driver->remove_order == order) { + if (comp->driver->remove_order == order) soc_remove_component(comp); - /* remove it from the card's aux_comp_list */ - soc_unbind_aux_dev(comp); - } } } } @@ -1930,6 +1930,7 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
/* remove auxiliary devices */ soc_remove_aux_devices(card); + soc_unbind_aux_dev(card);
snd_soc_dapm_free(&card->dapm); soc_cleanup_card_debugfs(card);
participants (2)
-
Kuninori Morimoto
-
Mark Brown