[alsa-devel] [PATCH 00/28] ASoC: cleanup patches for soc-core

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 (28): ASoC: soc-core: use device_register() ASoC: soc-core: set component->debugfs_root NULL ASoC: soc-core: add comment for for_each_xxx ASoC: soc-core: check return value of snd_soc_add_dai_link() ASoC: soc-core: don't use for_each_card_links_safe() at snd_soc_find_dai_link() ASoC: soc-core: reuse rtdcom at snd_soc_rtdcom_add() ASoC: soc-core: don't check widget for snd_soc_dapm_new_controls() ASoC: soc-core: don't check controls for snd_soc_add_component_controls() ASoC: soc-core: don't check routes for snd_soc_dapm_add_routes() ASoC: soc-core: don't check controls for snd_soc_add_card_controls() ASoC: soc-core: call snd_soc_dapm_debugfs_init() at soc_init_card_debugfs() ASoC: soc-core: remove unneeded list_empty() check for snd_soc_try_rebind_card() ASoC: soc-core: remove verbose debug message from soc_bind_dai_link() ASoC: soc-core: remove duplicated soc_is_dai_link_bound() ASoC: soc-core: tidyup for card->deferred_resume_work ASoC: soc-core: initialize rtd->list ASoC: soc-core: define soc_dpcm_debugfs_add() for non CONFIG_DEBUG_FS ASoC: soc-core: dai_link check under soc_dpcm_debugfs_add() ASoC: soc-core: merge snd_soc_initialize_card_lists() ASoC: soc-core: remove unneeded dai_link check from snd_soc_remove_dai_link() ASoC: soc-core: add NOTE to snd_soc_rtdcom_lookup() ASoC: soc-core: don't call snd_soc_component_set_jack() ASoC: soc-core: don't alloc memory carelessly when creating debugfs ASoC: soc-core: soc_cleanup_card_resources() become void ASoC: soc-core: initialize component list ASoC: soc-core: initialize list at one place ASoC: soc-dai: use bit field for bus_control ASoC: soc-topology: use for_each_component_dais() at remove_dai()
include/sound/soc-dai.h | 3 +- include/sound/soc-dpcm.h | 9 ++- include/sound/soc.h | 15 +--- sound/soc/soc-core.c | 196 ++++++++++++++++++++++------------------------- sound/soc/soc-pcm.c | 3 + sound/soc/soc-topology.c | 2 +- 6 files changed, 108 insertions(+), 120 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.
soc-core.c is using device_unregiser(), but there is no its paired device_regiser(). We can find its code at soc_post_component_init() which is using device_initialize() and device_add(). Here, device_initialize() + device_add() = device_register().
device_initialize() is doing each dev member's initialization only. So, the timing is not important here. let's use device_register() instead of device_initialize()/device_add().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0f75dac..40bac40 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1336,7 +1336,6 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); if (!rtd->dev) return -ENOMEM; - device_initialize(rtd->dev); rtd->dev->parent = rtd->card->dev; rtd->dev->release = rtd_release; rtd->dev->groups = soc_dev_attr_groups; @@ -1347,7 +1346,7 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); - ret = device_add(rtd->dev); + ret = device_register(rtd->dev); if (ret < 0) { /* calling put_device() here to free the rtd->dev */ put_device(rtd->dev);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
To be more safety code, let's set NULL to component->debugfs_root when it was cleanuped.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 40bac40..00887f7 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -171,7 +171,10 @@ static void soc_init_component_debugfs(struct snd_soc_component *component)
static void soc_cleanup_component_debugfs(struct snd_soc_component *component) { + if (!component->debugfs_root) + return; debugfs_remove_recursive(component->debugfs_root); + component->debugfs_root = NULL; }
static int dai_list_show(struct seq_file *m, void *v)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 40bac40..00887f7 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -171,7 +171,10 @@ static void soc_init_component_debugfs(struct snd_soc_component *component)
static void soc_cleanup_component_debugfs(struct snd_soc_component *component) {
- if (!component->debugfs_root)
return;
that test is redundant, it's safe to call debugfs_remove_recursive() without checking the argument (done internally).
debugfs_remove_recursive(component->debugfs_root);
- component->debugfs_root = NULL; }

On Tue, Aug 06, 2019 at 09:49:20AM -0500, Pierre-Louis Bossart wrote:
{
- if (!component->debugfs_root)
return;
that test is redundant, it's safe to call debugfs_remove_recursive() without checking the argument (done internally).
It's not completely redundant...
debugfs_remove_recursive(component->debugfs_root);
- component->debugfs_root = NULL; }
...with this, the two in combination add protection against a double free. Not 100% sure it's worth it but I queued the patch since I couldn't strongly convince myself it's a bad idea.

On 8/6/19 11:22 AM, Mark Brown wrote:
On Tue, Aug 06, 2019 at 09:49:20AM -0500, Pierre-Louis Bossart wrote:
{
- if (!component->debugfs_root)
return;
that test is redundant, it's safe to call debugfs_remove_recursive() without checking the argument (done internally).
It's not completely redundant...
debugfs_remove_recursive(component->debugfs_root);
- component->debugfs_root = NULL; }
...with this, the two in combination add protection against a double free. Not 100% sure it's worth it but I queued the patch since I couldn't strongly convince myself it's a bad idea.
I was only referring to the first test, which will be duplicated. see below. The second part is just fine.
/** * debugfs_remove_recursive - recursively removes a directory * @dentry: a pointer to a the dentry of the directory to be removed. If this * parameter is NULL or an error value, nothing will be done. * * This function recursively removes a directory tree in debugfs that * was previously created with a call to another debugfs function * (like debugfs_create_file() or variants thereof.) * * This function is required to be called in order for the file to be * removed, no automatic cleanup of files will happen when a module is * removed, you are responsible here. */ void debugfs_remove_recursive(struct dentry *dentry) { struct dentry *child, *parent;
if (IS_ERR_OR_NULL(dentry)) return;

On Tue, Aug 06, 2019 at 11:46:28AM -0500, Pierre-Louis Bossart wrote:
On 8/6/19 11:22 AM, Mark Brown wrote:
...with this, the two in combination add protection against a double free. Not 100% sure it's worth it but I queued the patch since I couldn't strongly convince myself it's a bad idea.
I was only referring to the first test, which will be duplicated. see below. The second part is just fine.
{ struct dentry *child, *parent;
if (IS_ERR_OR_NULL(dentry)) return;
Oh, I see it's got a NULL test in it. TBH I don't think it hurts to check in the caller, it avoids someone having to check to make sure that the NULL check is in the function.

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc-core has many for_each_xxx, but it is a little bit difficult to know which list is relead to which for_each_xxx. This patch adds missing comment for it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 00887f7..c46a617 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -380,6 +380,7 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd) static void soc_add_pcm_runtime(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd) { + /* see for_each_card_rtds */ list_add_tail(&rtd->list, &card->rtd_list); rtd->num = card->num_rtd; card->num_rtd++; @@ -1149,6 +1150,7 @@ int snd_soc_add_dai_link(struct snd_soc_card *card, if (dai_link->dobj.type && card->add_dai_link) card->add_dai_link(card, dai_link);
+ /* see for_each_card_links */ list_add_tail(&dai_link->list, &card->dai_link_list);
return 0;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_add_dai_link() might return error, we need to check it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c46a617..315c80d 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1963,8 +1963,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) }
/* add predefined DAI links to the list */ - for_each_card_prelinks(card, i, dai_link) - snd_soc_add_dai_link(card, dai_link); + for_each_card_prelinks(card, i, dai_link) { + ret = snd_soc_add_dai_link(card, dai_link); + if (ret < 0) + goto probe_end; + }
/* card bind complete so register a sound card */ ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
It doesn't removes list during loop at snd_soc_find_dai_link(). We don't need to use _safe loop.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 315c80d..05e8df2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -817,11 +817,11 @@ struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card, int id, const char *name, const char *stream_name) { - struct snd_soc_dai_link *link, *_link; + struct snd_soc_dai_link *link;
lockdep_assert_held(&client_mutex);
- for_each_card_links_safe(card, link, _link) { + for_each_card_links(card, link) { if (link->id != id) continue;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_rtdcom_add() is using both "rtdcom" and "new_rtdcom" as variable name, but these are not used at same time. Let's reuse rtdcom.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 05e8df2..6347d65 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -274,7 +274,6 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, struct snd_soc_component *component) { struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_rtdcom_list *new_rtdcom;
for_each_rtdcom(rtd, rtdcom) { /* already connected */ @@ -282,14 +281,14 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, return 0; }
- new_rtdcom = kmalloc(sizeof(*new_rtdcom), GFP_KERNEL); - if (!new_rtdcom) + rtdcom = kmalloc(sizeof(*rtdcom), GFP_KERNEL); + if (!rtdcom) return -ENOMEM;
- new_rtdcom->component = component; - INIT_LIST_HEAD(&new_rtdcom->list); + rtdcom->component = component; + INIT_LIST_HEAD(&rtdcom->list);
- list_add_tail(&new_rtdcom->list, &rtd->component_list); + list_add_tail(&rtdcom->list, &rtd->component_list);
return 0; }

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_dapm_new_controls() registers controls by using for(... i < num; ...). It means if widget was NULL, num should be zero. Thus, we don't need to check about widget pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 6347d65..bdd6a2e 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1264,16 +1264,14 @@ static int soc_probe_component(struct snd_soc_card *card,
soc_init_component_debugfs(component);
- if (component->driver->dapm_widgets) { - ret = snd_soc_dapm_new_controls(dapm, + 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; - } + if (ret != 0) { + dev_err(component->dev, + "Failed to create new controls %d\n", ret); + goto err_probe; }
for_each_component_dais(component, dai) { @@ -1989,13 +1987,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); #endif
- if (card->dapm_widgets) - snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, - card->num_dapm_widgets); + snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, + card->num_dapm_widgets);
- if (card->of_dapm_widgets) - snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, - card->num_of_dapm_widgets); + snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, + card->num_of_dapm_widgets);
/* initialise the sound card only once */ if (card->probe) {

On Tue, 2019-08-06 at 10:28 +0900, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_dapm_new_controls() registers controls by using for(... i < num; ...). It means if widget was NULL, num should be zero. Thus, we don't need to check about widget pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 6347d65..bdd6a2e 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1264,16 +1264,14 @@ static int soc_probe_component(struct snd_soc_card *card,
soc_init_component_debugfs(component);
- if (component->driver->dapm_widgets) {
ret = snd_soc_dapm_new_controls(dapm,
- 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;
}
if (ret != 0) {
dev_err(component->dev,
"Failed to create new controls %d\n", ret);
goto err_probe;
}
for_each_component_dais(component, dai) {
@@ -1989,13 +1987,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); #endif
- if (card->dapm_widgets)
snd_soc_dapm_new_controls(&card->dapm, card-
dapm_widgets,
card->num_dapm_widgets);
- snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
card->num_dapm_widgets);
Should the return value be checked here?
- if (card->of_dapm_widgets)
snd_soc_dapm_new_controls(&card->dapm, card-
of_dapm_widgets,
card->num_of_dapm_widgets);
- snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
card->num_of_dapm_widgets);
and here?
Thanks, Ranjani

On Mon, Aug 05, 2019 at 09:35:58PM -0700, Ranjani Sridharan wrote:
On Tue, 2019-08-06 at 10:28 +0900, Kuninori Morimoto wrote:
- if (card->dapm_widgets)
snd_soc_dapm_new_controls(&card->dapm, card-
dapm_widgets,
card->num_dapm_widgets);
- snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
card->num_dapm_widgets);
Should the return value be checked here?
Preexisting bug but yes.

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_add_component_controls() registers controls by using for(... i < num; ...). If controls was NULL, num should be zero. Thus, we don't need to check about controls pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index bdd6a2e..7be8385 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1304,10 +1304,9 @@ static int soc_probe_component(struct snd_soc_card *card, } }
- if (component->driver->controls) - snd_soc_add_component_controls(component, - component->driver->controls, - component->driver->num_controls); + snd_soc_add_component_controls(component, + component->driver->controls, + component->driver->num_controls); if (component->driver->dapm_routes) snd_soc_dapm_add_routes(dapm, component->driver->dapm_routes,

On Tue, 2019-08-06 at 10:28 +0900, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_add_component_controls() registers controls by using for(... i < num; ...). If controls was NULL, num should be zero. Thus, we don't need to check about controls pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index bdd6a2e..7be8385 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1304,10 +1304,9 @@ static int soc_probe_component(struct snd_soc_card *card, } }
- if (component->driver->controls)
snd_soc_add_component_controls(component,
component->driver-
controls,
component->driver-
num_controls);
- snd_soc_add_component_controls(component,
component->driver->controls,
component->driver-
num_controls);
Should the return value be checked?
Thanks, Ranjani
if (component->driver->dapm_routes) snd_soc_dapm_add_routes(dapm, component->driver->dapm_routes,

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_dapm_add_routes() registers routes by using for(... i < num; ...). If routes was NULL, num should be zero. Thus, we don't need to check about route pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 7be8385..5b26a59 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1307,10 +1307,9 @@ static int soc_probe_component(struct snd_soc_card *card, snd_soc_add_component_controls(component, component->driver->controls, component->driver->num_controls); - if (component->driver->dapm_routes) - snd_soc_dapm_add_routes(dapm, - component->driver->dapm_routes, - component->driver->num_dapm_routes); + snd_soc_dapm_add_routes(dapm, + component->driver->dapm_routes, + component->driver->num_dapm_routes);
list_add(&dapm->list, &card->dapm_list); /* see for_each_card_components */ @@ -2053,13 +2052,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) snd_soc_add_card_controls(card, card->controls, card->num_controls);
- if (card->dapm_routes) - snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, - card->num_dapm_routes); + snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, + card->num_dapm_routes);
- if (card->of_dapm_routes) - snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, - card->num_of_dapm_routes); + snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, + card->num_of_dapm_routes);
/* try to set some sane longname if DMI is available */ snd_soc_set_dmi_name(card, NULL);

On Tue, 2019-08-06 at 10:28 +0900, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_dapm_add_routes() registers routes by using for(... i < num; ...). If routes was NULL, num should be zero. Thus, we don't need to check about route pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 7be8385..5b26a59 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1307,10 +1307,9 @@ static int soc_probe_component(struct snd_soc_card *card, snd_soc_add_component_controls(component, component->driver->controls, component->driver-
num_controls);
- if (component->driver->dapm_routes)
snd_soc_dapm_add_routes(dapm,
component->driver->dapm_routes,
component->driver-
num_dapm_routes);
- snd_soc_dapm_add_routes(dapm,
component->driver->dapm_routes,
component->driver->num_dapm_routes);
return value needs to be checked for all the snd_soc_dapm_add_routes() calls?
Thanks, Ranjani
list_add(&dapm->list, &card->dapm_list); /* see for_each_card_components */ @@ -2053,13 +2052,11 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) snd_soc_add_card_controls(card, card->controls, card->num_controls);
- if (card->dapm_routes)
snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
card->num_dapm_routes);
- snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
card->num_dapm_routes);
- if (card->of_dapm_routes)
snd_soc_dapm_add_routes(&card->dapm, card-
of_dapm_routes,
card->num_of_dapm_routes);
snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
card->num_of_dapm_routes);
/* try to set some sane longname if DMI is available */ snd_soc_set_dmi_name(card, NULL);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_add_card_controls() registers controls by using for(... i < num; ...). If controls was NULL, num should be zero. Thus, we don't need to check about controls pointer.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 5b26a59..f138c83 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2048,9 +2048,8 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) snd_soc_dapm_link_dai_widgets(card); snd_soc_dapm_connect_dai_link_widgets(card);
- if (card->controls) - snd_soc_add_card_controls(card, card->controls, - card->num_controls); + snd_soc_add_card_controls(card, card->controls, + card->num_controls);
snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, card->num_dapm_routes);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
We have 2 soc_init_card_debugfs() implementations for with/without DEBUG_FS. But, snd_soc_instantiate_card() calls snd_soc_dapm_debugfs_init() under ifdef DEBUG_FS after soc_init_card_debugfs(). This is very strange. We can call snd_soc_dapm_debugfs_init() under soc_init_card_debugfs().
#ifdef CONFIG_DEBUG_FS => static void soc_init_card_debugfs(...) { ... } ... #else => static inline void soc_init_card_debugfs(...) { ... } #endif
static int snd_soc_instantiate_card(struct snd_soc_card *card) { ... => soc_init_card_debugfs(card);
* #ifdef CONFIG_DEBUG_FS * snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); * #endif }
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index f138c83..327a3a6 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -216,6 +216,8 @@ static void soc_init_card_debugfs(struct snd_soc_card *card)
debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root, &card->pop_time); + + snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); }
static void soc_cleanup_card_debugfs(struct snd_soc_card *card) @@ -1976,10 +1978,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
soc_init_card_debugfs(card);
-#ifdef CONFIG_DEBUG_FS - snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); -#endif - #ifdef CONFIG_PM_SLEEP /* deferred resume work */ INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
list_for_each_entry_safe() will do nothing if it was empty list. This patch removes unneeded list_empty() check for list_for_each_entry_safe().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 327a3a6..df0c22e 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2792,12 +2792,9 @@ static void snd_soc_try_rebind_card(void) { struct snd_soc_card *card, *c;
- if (!list_empty(&unbind_card_list)) { - list_for_each_entry_safe(card, c, &unbind_card_list, list) { - if (!snd_soc_bind_card(card)) - list_del(&card->list); - } - } + list_for_each_entry_safe(card, c, &unbind_card_list, list) + if (!snd_soc_bind_card(card)) + list_del(&card->list); }
int snd_soc_add_component(struct device *dev,

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc_bind_dai_link() will print debug message if dai_link was already binded. But it is very verbose. Print dai_link name when first binding is very enough. This patch removes verbose debug message
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index df0c22e..838a843 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -864,13 +864,10 @@ static int soc_bind_dai_link(struct snd_soc_card *card, if (dai_link->ignore) return 0;
- dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name); - - if (soc_is_dai_link_bound(card, dai_link)) { - dev_dbg(card->dev, "ASoC: dai link %s already bound\n", - dai_link->name); + if (soc_is_dai_link_bound(card, dai_link)) return 0; - } + + dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
rtd = soc_new_pcm_runtime(card, dai_link); if (!rtd)

On 8/5/19 8:29 PM, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc_bind_dai_link() will print debug message if dai_link was already binded. But it is very verbose. Print dai_link name when first binding is very enough. This patch removes verbose debug message
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index df0c22e..838a843 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -864,13 +864,10 @@ static int soc_bind_dai_link(struct snd_soc_card *card, if (dai_link->ignore) return 0;
- dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
- if (soc_is_dai_link_bound(card, dai_link)) {
dev_dbg(card->dev, "ASoC: dai link %s already bound\n",
dai_link->name);
- if (soc_is_dai_link_bound(card, dai_link)) return 0;
- }
- dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
If you want to reduce verbosity, I would have kept the other message which tells you about a configuration error. Here you are reducing the ability to debug really.
rtd = soc_new_pcm_runtime(card, dai_link); if (!rtd)

Hi Pierre-Louis
Thank you for your feedback !!
@@ -864,13 +864,10 @@ static int soc_bind_dai_link(struct snd_soc_card *card, if (dai_link->ignore) return 0;
- dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
- if (soc_is_dai_link_bound(card, dai_link)) {
dev_dbg(card->dev, "ASoC: dai link %s already bound\n",
dai_link->name);
- if (soc_is_dai_link_bound(card, dai_link)) return 0;
- }
- dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
If you want to reduce verbosity, I would have kept the other message which tells you about a configuration error. Here you are reducing the ability to debug really.
I thought it is verbose. But, let's keep it, if some one need it.
Thank you for your help !! Best regards --- Kuninori Morimoto

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc_is_dai_link_bound() check will be called both *before* soc_bind_dai_link(), and *under* soc_bind_dai_link(). These are very verboqse. Let's remove one of them.
* static int soc_bind_dai_link(...) { ... => if (soc_is_dai_link_bound(...)) { ... return 0; } ... }
static int snd_soc_instantiate_card(...) { ... for_each_card_links(...) { => if (soc_is_dai_link_bound(...)) => continue; ... * ret = soc_bind_dai_link(...); if (ret) goto probe_end; } ... }
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 838a843..e8ed57a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2016,9 +2016,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) * Components with topology may bring new DAIs and DAI links. */ for_each_card_links(card, dai_link) { - if (soc_is_dai_link_bound(card, dai_link)) - continue; - ret = soc_init_dai_link(card, dai_link); if (ret) goto probe_end;

On Tue, 2019-08-06 at 10:29 +0900, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc_is_dai_link_bound() check will be called both *before* soc_bind_dai_link(), and *under* soc_bind_dai_link(). These are very verboqse. Let's remove one of them.
- static int soc_bind_dai_link(...) { ...
=> if (soc_is_dai_link_bound(...)) { ... return 0; } ... }
static int snd_soc_instantiate_card(...) { ... for_each_card_links(...) { => if (soc_is_dai_link_bound(...)) => continue; ...
} ... }ret = soc_bind_dai_link(...); if (ret) goto probe_end;
Morimoto-san,
I think we should keep both the calls. The call to check if (soc_is_dai_link_bound(...)) will prevent soc_init_dai_link() if the dai link is already bound.
Thanks, Ranjani
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 838a843..e8ed57a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2016,9 +2016,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) * Components with topology may bring new DAIs and DAI links. */ for_each_card_links(card, dai_link) {
if (soc_is_dai_link_bound(card, dai_link))
continue;
- ret = soc_init_dai_link(card, dai_link); if (ret) goto probe_end;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
card->deferred_resume_work is used if CONFIG_PM_SLEEP was defined. but 1) It is defined even though CONFIG_PM_SLEEP was not defined 2) randam ifdef code is difficlut to read. This patch tidyup these issues.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 5 +++-- sound/soc/soc-core.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 6ac6481..85ad971 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1058,8 +1058,6 @@ struct snd_soc_card { int num_of_dapm_routes; bool fully_routed;
- struct work_struct deferred_resume_work; - /* lists of probed devices belonging to this card */ struct list_head component_dev_list; struct list_head list; @@ -1080,6 +1078,9 @@ struct snd_soc_card { #ifdef CONFIG_DEBUG_FS struct dentry *debugfs_card_root; #endif +#ifdef CONFIG_PM_SLEEP + struct work_struct deferred_resume_work; +#endif u32 pop_time;
void *drvdata; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e8ed57a..2536ba4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -701,9 +701,18 @@ int snd_soc_resume(struct device *dev) return 0; } EXPORT_SYMBOL_GPL(snd_soc_resume); + +static void soc_resume_init(struct snd_soc_card *card) +{ + /* deferred resume work */ + INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); +} #else #define snd_soc_suspend NULL #define snd_soc_resume NULL +static inline void soc_resume_init(struct snd_soc_card *card) +{ +} #endif
static const struct snd_soc_dai_ops null_dai_ops = { @@ -1975,10 +1984,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
soc_init_card_debugfs(card);
-#ifdef CONFIG_PM_SLEEP - /* deferred resume work */ - INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); -#endif + soc_resume_init(card);
snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, card->num_dapm_widgets);

On 8/5/19 8:29 PM, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
card->deferred_resume_work is used if CONFIG_PM_SLEEP was defined. but
- It is defined even though CONFIG_PM_SLEEP was not defined
- randam ifdef code is difficlut to read.
typos: random .. difficult
This patch tidyup these issues.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
include/sound/soc.h | 5 +++-- sound/soc/soc-core.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 6ac6481..85ad971 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1058,8 +1058,6 @@ struct snd_soc_card { int num_of_dapm_routes; bool fully_routed;
- struct work_struct deferred_resume_work;
- /* lists of probed devices belonging to this card */ struct list_head component_dev_list; struct list_head list;
@@ -1080,6 +1078,9 @@ struct snd_soc_card { #ifdef CONFIG_DEBUG_FS struct dentry *debugfs_card_root; #endif +#ifdef CONFIG_PM_SLEEP
- struct work_struct deferred_resume_work;
+#endif u32 pop_time;
void *drvdata; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e8ed57a..2536ba4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -701,9 +701,18 @@ int snd_soc_resume(struct device *dev) return 0; } EXPORT_SYMBOL_GPL(snd_soc_resume);
+static void soc_resume_init(struct snd_soc_card *card) +{
- /* deferred resume work */
- INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
+} #else #define snd_soc_suspend NULL #define snd_soc_resume NULL +static inline void soc_resume_init(struct snd_soc_card *card) +{ +} #endif
static const struct snd_soc_dai_ops null_dai_ops = { @@ -1975,10 +1984,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
soc_init_card_debugfs(card);
-#ifdef CONFIG_PM_SLEEP
- /* deferred resume work */
- INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
-#endif
soc_resume_init(card);
snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, card->num_dapm_widgets);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
No one initialize rtd->list, so far. Let's do it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2536ba4..2347b58 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -354,6 +354,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( if (!rtd) return NULL;
+ INIT_LIST_HEAD(&rtd->list); INIT_LIST_HEAD(&rtd->component_list); rtd->card = card; rtd->dai_link = dai_link;

On Tue, 2019-08-06 at 10:29 +0900, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
No one initialize rtd->list, so far. Let's do it.
Morimoto-san,
I dont think this is needed. The rtd->list is not meant to be a list but rather just as a member of the card->rtd_list. So no need to initialize.
Thanks, Ranjani
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2536ba4..2347b58 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -354,6 +354,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( if (!rtd) return NULL;
- INIT_LIST_HEAD(&rtd->list); INIT_LIST_HEAD(&rtd->component_list); rtd->card = card; rtd->dai_link = dai_link;

Hi Ranjani
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
No one initialize rtd->list, so far. Let's do it.
Morimoto-san,
I dont think this is needed. The rtd->list is not meant to be a list but rather just as a member of the card->rtd_list. So no need to initialize.
Thank you for your review !
I will wait other peoples review, and post v2 patch.
Thank you for your help !! Best regards --- Kuninori Morimoto

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc_dpcm_debugfs_add() is implemented at soc-pcm.c under CONFIG_DEBUG_FS. Thus, soc-core.c which is only user of it need to use CONFIG_DEBUG_FS, too.
This patch defines soc_dpcm_debugfs_add() for non CONFIG_DEBUG_FS case. Then, we can remove #ifdef CONFIG_DEBUG_FS from soc-core.c
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc-dpcm.h | 9 ++++++++- sound/soc/soc-core.c | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h index 4be3a2b..e55aeb0 100644 --- a/include/sound/soc-dpcm.h +++ b/include/sound/soc-dpcm.h @@ -142,9 +142,16 @@ void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,
/* internal use only */ int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute); -void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd); int soc_dpcm_runtime_update(struct snd_soc_card *);
+#ifdef CONFIG_DEBUG_FS +void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd); +#else +static inline void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) +{ +} +#endif + int dpcm_path_get(struct snd_soc_pcm_runtime *fe, int stream, struct snd_soc_dapm_widget_list **list_); int dpcm_process_paths(struct snd_soc_pcm_runtime *fe, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2347b58..724e376 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1479,11 +1479,9 @@ static int soc_probe_link_dais(struct snd_soc_card *card, if (ret) return ret;
-#ifdef CONFIG_DEBUG_FS /* add DPCM sysfs entries */ if (dai_link->dynamic) soc_dpcm_debugfs_add(rtd); -#endif
num = rtd->num;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
soc_dpcm_debugfs_add(rtd) is checking rtd->dai_link pointer, but, rtd->dai_link->dynamic have been already checked before calling it.
static int soc_probe_link_dais(...) { dai_link = rtd->dai_link; ... => if (dai_link->dynamic) => soc_dpcm_debugfs_add(rtd); ... }
void soc_dpcm_debugfs_add(rtd) { => if (!rtd->dai_link) return; ... }
These pointer checks are strange/pointless. This patch checks dai_link->dynamic under soc_dpcm_debugfs_add().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 3 +-- sound/soc/soc-pcm.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 724e376..188b60c 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1480,8 +1480,7 @@ static int soc_probe_link_dais(struct snd_soc_card *card, return ret;
/* add DPCM sysfs entries */ - if (dai_link->dynamic) - soc_dpcm_debugfs_add(rtd); + soc_dpcm_debugfs_add(rtd);
num = rtd->num;
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 77c986f..da657c8 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -3200,6 +3200,9 @@ void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd) if (!rtd->dai_link) return;
+ if (!rtd->dai_link->dynamic) + return; + if (!rtd->card->debugfs_card_root) return;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_initialize_card_lists() is doing card related INIT_LIST_HEAD(), but, it is already doing at snd_soc_register_card(). We don't need to do it separately. This patch merges these.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc.h | 10 ---------- sound/soc/soc-core.c | 13 ++++++++----- 2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 85ad971..c92697e 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1210,16 +1210,6 @@ static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card) return card->drvdata; }
-static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card) -{ - INIT_LIST_HEAD(&card->widgets); - INIT_LIST_HEAD(&card->paths); - INIT_LIST_HEAD(&card->dapm_list); - INIT_LIST_HEAD(&card->aux_comp_list); - INIT_LIST_HEAD(&card->component_dev_list); - INIT_LIST_HEAD(&card->list); -} - static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc) { if (mc->reg == mc->rreg && mc->shift == mc->rshift) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 188b60c..030573b 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2369,15 +2369,18 @@ int snd_soc_register_card(struct snd_soc_card *card)
dev_set_drvdata(card->dev, card);
- snd_soc_initialize_card_lists(card); - + INIT_LIST_HEAD(&card->widgets); + INIT_LIST_HEAD(&card->paths); + INIT_LIST_HEAD(&card->dapm_list); + INIT_LIST_HEAD(&card->aux_comp_list); + INIT_LIST_HEAD(&card->component_dev_list); + INIT_LIST_HEAD(&card->list); INIT_LIST_HEAD(&card->dai_link_list); - INIT_LIST_HEAD(&card->rtd_list); - card->num_rtd = 0; - INIT_LIST_HEAD(&card->dapm_dirty); INIT_LIST_HEAD(&card->dobj_list); + + card->num_rtd = 0; card->instantiated = 0; mutex_init(&card->mutex); mutex_init(&card->dapm_mutex);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_remove_dai_link() has card connected dai_link check. but 1) we need to call list_del() anyway, because it is "remove" function, 2) It is doing many thing for this card / dai_link already before checking dai_link.
This patch removes poinless dai_link check
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 030573b..61a973f 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1178,8 +1178,6 @@ EXPORT_SYMBOL_GPL(snd_soc_add_dai_link); void snd_soc_remove_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link) { - struct snd_soc_dai_link *link, *_link; - if (dai_link->dobj.type && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) { dev_err(card->dev, "Invalid dai link type %d\n", @@ -1195,12 +1193,7 @@ void snd_soc_remove_dai_link(struct snd_soc_card *card, if (dai_link->dobj.type && card->remove_dai_link) card->remove_dai_link(card, dai_link);
- for_each_card_links_safe(card, link, _link) { - if (link == dai_link) { - list_del(&link->list); - return; - } - } + list_del(&dai_link->list); } EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
We can find specified name component via snd_soc_rtdcom_lookup(). But, it is not enough under multi CPU/Codec/Platform, because many components which have same driver name might be connected to same rtd.
Not using this function as much as possible is best solution, but some drivers are already deeply depended to it.
We can expand this function, for example having "num" which specifies found order at parameter, etc (In such case, it need to have fixed probing order). Or, use different driver name in such component, etc.
We will have such issue if multi CPU/Codec/Platform were supported. To indicate it, this patch adds NOTE to this function.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 61a973f..ee63ccf 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -313,6 +313,14 @@ 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_rtdcom(rtd, rtdcom) { const char *component_name = rtdcom->component->driver->name;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_component_set_jack() is used for both setting/clearing. Setting purpose is used under each driver. Hence, clearing purpose should be used under each driver, not soc-core.
soc-core shouldn't touch it even though its purpose was for clearing, otherwise, code becomes very confusable. This patch removes snd_soc_component_set_jack() from soc-core.c
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ee63ccf..c737349 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -936,7 +936,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
static void soc_cleanup_component(struct snd_soc_component *component) { - snd_soc_component_set_jack(component, NULL, NULL); list_del(&component->card_list); snd_soc_dapm_free(snd_soc_component_get_dapm(component)); soc_cleanup_component_debugfs(component);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current ALSA SoC might allocate debugfs name memory via kasprintf(), but, it is grandiose and the code becoming very complex. Using enough size local variable is very enough for this purpose.
This patch uses 64byte local variable for it. It is very enough size for this purposeq.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c737349..bf3bda2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -147,23 +147,19 @@ static const struct attribute_group *soc_dev_attr_groups[] = { #ifdef CONFIG_DEBUG_FS static void soc_init_component_debugfs(struct snd_soc_component *component) { + char name[64]; + if (!component->card->debugfs_card_root) return;
- if (component->debugfs_prefix) { - char *name; - - name = kasprintf(GFP_KERNEL, "%s:%s", + if (component->debugfs_prefix) + snprintf(name, ARRAY_SIZE(name), "%s:%s", component->debugfs_prefix, component->name); - if (name) { - component->debugfs_root = debugfs_create_dir(name, - component->card->debugfs_card_root); - kfree(name); - } - } else { - component->debugfs_root = debugfs_create_dir(component->name, - component->card->debugfs_card_root); - } + else + snprintf(name, ARRAY_SIZE(name), "%s", component->name); + + component->debugfs_root = debugfs_create_dir(name, + component->card->debugfs_card_root);
snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), component->debugfs_root);

On 8/5/19 8:30 PM, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Current ALSA SoC might allocate debugfs name memory via kasprintf(), but, it is grandiose and the code becoming very complex.
grandiose sounds lyric. did you mean unnecessary?
Using enough size local variable is very enough for this purpose.
Using local variable with appropriate size is enough.
This patch uses 64byte local variable for it. It is very enough size for this purposeq.
last sentence is redundant
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c737349..bf3bda2 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -147,23 +147,19 @@ static const struct attribute_group *soc_dev_attr_groups[] = { #ifdef CONFIG_DEBUG_FS static void soc_init_component_debugfs(struct snd_soc_component *component) {
- char name[64];
- if (!component->card->debugfs_card_root) return;
- if (component->debugfs_prefix) {
char *name;
name = kasprintf(GFP_KERNEL, "%s:%s",
- if (component->debugfs_prefix)
snprintf(name, ARRAY_SIZE(name), "%s:%s", component->debugfs_prefix, component->name);
if (name) {
component->debugfs_root = debugfs_create_dir(name,
component->card->debugfs_card_root);
kfree(name);
}
- } else {
component->debugfs_root = debugfs_create_dir(component->name,
component->card->debugfs_card_root);
- }
else
snprintf(name, ARRAY_SIZE(name), "%s", component->name);
component->debugfs_root = debugfs_create_dir(name,
component->card->debugfs_card_root);
snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), component->debugfs_root);

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
There is no need to check return value for soc_cleanup_card_resources(). Let't makes it as void.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index bf3bda2..75b1770 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1894,7 +1894,7 @@ static void soc_check_tplg_fes(struct snd_soc_card *card) } }
-static int soc_cleanup_card_resources(struct snd_soc_card *card) +static void soc_cleanup_card_resources(struct snd_soc_card *card) { /* free the ALSA card at first; this syncs with pending operations */ if (card->snd_card) { @@ -1915,8 +1915,6 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card) /* remove the card */ if (card->remove) card->remove(card); - - return 0; }
static int snd_soc_instantiate_card(struct snd_soc_card *card)

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_component_initialize() isn't initialize component->list, but we should do it. This patch initialize it.
It might return without initializing in error case. In such case, uninitialized list might be used at error handler. This patch initializes all necessary variable before return.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 75b1770..666851b 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2641,6 +2641,10 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, { struct snd_soc_dapm_context *dapm;
+ INIT_LIST_HEAD(&component->dai_list); + INIT_LIST_HEAD(&component->list); + mutex_init(&component->io_mutex); + component->name = fmt_single_name(dev, &component->id); if (!component->name) { dev_err(dev, "ASoC: Failed to allocate name\n"); @@ -2657,9 +2661,6 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, dapm->idle_bias_off = !driver->idle_bias_on; dapm->suspend_bias_off = driver->suspend_bias_off;
- INIT_LIST_HEAD(&component->dai_list); - mutex_init(&component->io_mutex); - return 0; }

On 8/5/19 8:30 PM, Kuninori Morimoto wrote:
From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
snd_soc_component_initialize() isn't initialize component->list,
doesn't
but we should do it. This patch initialize it.
initializes
It might return without initializing in error case. In such case, uninitialized list might be used at error handler. This patch initializes all necessary variable before return.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
sound/soc/soc-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 75b1770..666851b 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2641,6 +2641,10 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, { struct snd_soc_dapm_context *dapm;
- INIT_LIST_HEAD(&component->dai_list);
- INIT_LIST_HEAD(&component->list);
is this actually required or is this 'list' used for list management?
- mutex_init(&component->io_mutex);
- component->name = fmt_single_name(dev, &component->id); if (!component->name) { dev_err(dev, "ASoC: Failed to allocate name\n");
@@ -2657,9 +2661,6 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, dapm->idle_bias_off = !driver->idle_bias_on; dapm->suspend_bias_off = driver->suspend_bias_off;
- INIT_LIST_HEAD(&component->dai_list);
- mutex_init(&component->io_mutex);
- return 0; }

Hi Pierre-Louis
Thank you for your English lesson :)
snd_soc_component_initialize() isn't initialize component->list,
doesn't
but we should do it. This patch initialize it.
initializes
Thanks ! I will fix these, and [15/28], [23/28] too
@@ -2641,6 +2641,10 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, { struct snd_soc_dapm_context *dapm;
- INIT_LIST_HEAD(&component->dai_list);
- INIT_LIST_HEAD(&component->list);
is this actually required or is this 'list' used for list management?
Ahh, maybe be this is same comment for [16/28] from Ranjani. I will fix it and Subject.
Thank you for your help !! Best regards --- Kuninori Morimoto

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
Initialize component related list at random place is very difficult to read. This patch initialize it at snd_soc_component_initialize().
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 666851b..ef0f2d3 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1263,7 +1263,6 @@ static int soc_probe_component(struct snd_soc_card *card,
component->card = card; dapm->card = card; - INIT_LIST_HEAD(&component->card_list); INIT_LIST_HEAD(&dapm->list); soc_set_name_prefix(card, component);
@@ -2643,6 +2642,8 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
INIT_LIST_HEAD(&component->dai_list); INIT_LIST_HEAD(&component->list); + INIT_LIST_HEAD(&component->dobj_list); + INIT_LIST_HEAD(&component->card_list); mutex_init(&component->io_mutex);
component->name = fmt_single_name(dev, &component->id); @@ -2728,7 +2729,6 @@ static void snd_soc_component_add(struct snd_soc_component *component)
/* see for_each_component */ list_add(&component->list, &component_list); - INIT_LIST_HEAD(&component->dobj_list);
mutex_unlock(&client_mutex); }

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
.bus_control can be bit field. this patch do it.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- include/sound/soc-dai.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index dc48fe0..939c73d 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -293,8 +293,6 @@ struct snd_soc_dai_driver { /* Optional Callback used at pcm creation*/ int (*pcm_new)(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai); - /* DAI is also used for the control bus */ - bool bus_control;
/* ops */ const struct snd_soc_dai_ops *ops; @@ -306,6 +304,7 @@ struct snd_soc_dai_driver { unsigned int symmetric_rates:1; unsigned int symmetric_channels:1; unsigned int symmetric_samplebits:1; + unsigned int bus_control:1; /* DAI is also used for the control bus */
/* probe ordering - for components with runtime dependencies */ int probe_order;

From: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
commit 52abe6cc1866a ("ASoC: topology: fix oops/use-after-free case with dai driver") fixups remove_dai() error, but it is using list_for_each_entry() for component->dai_list.
We already have for_each_component_dais() macro for it. Let's use exising method.
Signed-off-by: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- sound/soc/soc-topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index dc463f1..b869071 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -530,7 +530,7 @@ static void remove_dai(struct snd_soc_component *comp, if (dobj->ops && dobj->ops->dai_unload) dobj->ops->dai_unload(comp, dobj);
- list_for_each_entry(dai, &comp->dai_list, list) + for_each_component_dais(comp, dai) if (dai->driver == dai_drv) dai->driver = NULL;
participants (4)
-
Kuninori Morimoto
-
Mark Brown
-
Pierre-Louis Bossart
-
Ranjani Sridharan