[PATCH] ASoC: soc-core: use client_mutex for snd_soc_find_dai()

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Tue Aug 18 04:37:29 CEST 2020


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

commit 25612477d20b52 ("ASoC: soc-dai: set dai_link dpcm_ flags with a helper")
added snd_soc_dai_link_set_capabilities().
But it is using snd_soc_find_dai() (A) which is required client_mutex (B).
And client_mutex is soc-core.c local.

	struct snd_soc_dai *snd_soc_find_dai(xxx)
	{
		...
(B)		lockdep_assert_held(&client_mutex);
		...
	}

	void snd_soc_dai_link_set_capabilities(xxx)
	{
		...
		for_each_pcm_streams(direction) {
			...
			for_each_link_cpus(dai_link, i, cpu) {
(A)				dai = snd_soc_find_dai(cpu);
				...
			}
			...
			for_each_link_codecs(dai_link, i, codec) {
(A)				dai = snd_soc_find_dai(codec);
				...
			}
		}
		...
	}

Because of these background, we will get WARNING if .config has CONFIG_LOCKDEP.

	WARNING: CPU: 2 PID: 53 at sound/soc/soc-core.c:814 snd_soc_find_dai+0xf8/0x100
	CPU: 2 PID: 53 Comm: kworker/2:1 Not tainted 5.7.0-rc1+ #328
	Hardware name: Renesas H3ULCB Kingfisher board based on r8a77951 (DT)
	Workqueue: events deferred_probe_work_func
	pstate: 60000005 (nZCv daif -PAN -UAO)
	pc : snd_soc_find_dai+0xf8/0x100
	lr : snd_soc_find_dai+0xf4/0x100
	...
	Call trace:
	 snd_soc_find_dai+0xf8/0x100
	 snd_soc_dai_link_set_capabilities+0xa0/0x16c
	 graph_dai_link_of_dpcm+0x390/0x3c0
	 graph_for_each_link+0x134/0x200
	 graph_probe+0x144/0x230
	 platform_drv_probe+0x5c/0xb0
	 really_probe+0xe4/0x430
	 driver_probe_device+0x60/0xf4

Many drivers are already calling snd_soc_find_dai() and/or snd_soc_dai_link_set_capabilities().
Thus, same thing can be happen on these drivers, too.

	> grep snd_soc_find_dai -rl sound/soc/*
	sound/soc/samsung/tm2_wm5110.c
	sound/soc/soc-core.c
	sound/soc/soc-dai.c
	sound/soc/soc-topology.c
	sound/soc/sof/topology.c

	> grep snd_soc_dai_link_set_capabilities -rl sound/soc/*
	sound/soc/generic/simple-card.c
	sound/soc/generic/audio-graph-card.c
	sound/soc/qcom/common.c
	sound/soc/soc-dai.c

This patch renames current snd_soc_find_dai() to _no_mutex(),
and new snd_soc_find_dai() uses client_mutex.

Fixes: 25612477d20b52 ("ASoC: soc-dai: set dai_link dpcm_ flags with a helper")
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 sound/soc/soc-core.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fe23e936e2d1..6ea66b57b2c1 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -805,7 +805,7 @@ static struct snd_soc_component *soc_find_component(
  *
  * Return: pointer of DAI, or NULL if not found.
  */
-struct snd_soc_dai *snd_soc_find_dai(
+static struct snd_soc_dai *snd_soc_find_dai_no_mutex(
 	const struct snd_soc_dai_link_component *dlc)
 {
 	struct snd_soc_component *component;
@@ -829,6 +829,17 @@ struct snd_soc_dai *snd_soc_find_dai(
 
 	return NULL;
 }
+
+struct snd_soc_dai *snd_soc_find_dai(const struct snd_soc_dai_link_component *dlc)
+{
+	struct snd_soc_dai *dai;
+
+	mutex_lock(&client_mutex);
+	dai = snd_soc_find_dai_no_mutex(dlc);
+	mutex_unlock(&client_mutex);
+
+	return dai;
+}
 EXPORT_SYMBOL_GPL(snd_soc_find_dai);
 
 static int soc_dai_link_sanity_check(struct snd_soc_card *card,
@@ -999,7 +1010,7 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
 		return -ENOMEM;
 
 	for_each_link_cpus(dai_link, i, cpu) {
-		asoc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
+		asoc_rtd_to_cpu(rtd, i) = snd_soc_find_dai_no_mutex(cpu);
 		if (!asoc_rtd_to_cpu(rtd, i)) {
 			dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
 				 cpu->dai_name);
@@ -1010,7 +1021,7 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
 
 	/* Find CODEC from registered CODECs */
 	for_each_link_codecs(dai_link, i, codec) {
-		asoc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
+		asoc_rtd_to_codec(rtd, i) = snd_soc_find_dai_no_mutex(codec);
 		if (!asoc_rtd_to_codec(rtd, i)) {
 			dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
 				 codec->dai_name);
-- 
2.25.1



More information about the Alsa-devel mailing list