alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component()
@ 2019-11-06  7:05 Kuninori Morimoto
  2019-11-06 16:21 ` [alsa-devel] Applied "ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component()" to the asoc tree Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Kuninori Morimoto @ 2019-11-06  7:05 UTC (permalink / raw)
  To: Mark Brown
  Cc: alsa-devel, kernelci.org bot, tomeu.vizoso, Liam Girdwood,
	guillaume.tucker, Takashi Iwai, Ranjani Sridharan,
	Pierre-Louis Bossart, matthew.hart, mgalka, enric.balletbo,
	khilman, linux-kernel

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

snd_soc_unregister_component() is calling snd_soc_lookup_component()
under mutex_lock(). But, snd_soc_lookup_component() itself is using
mutex_lock(), thus it will be dead-lock.
This patch adds _nolocked version of it, and avoid dead-lock issue.

Fixes: ac6a4dd3e9f0("ASoC: soc-core: use snd_soc_lookup_component() at snd_soc_unregister_component()")
Reported-by: "kernelci.org bot" <bot@kernelci.org>"
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
> Please double check/test it.

 sound/soc/soc-core.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index cc59687..94f1078 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -356,14 +356,13 @@ struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
 }
 EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
 
-struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
-						   const char *driver_name)
+static struct snd_soc_component
+*snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
 {
 	struct snd_soc_component *component;
 	struct snd_soc_component *found_component;
 
 	found_component = NULL;
-	mutex_lock(&client_mutex);
 	for_each_component(component) {
 		if ((dev == component->dev) &&
 		    (!driver_name ||
@@ -373,10 +372,21 @@ struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
 			break;
 		}
 	}
-	mutex_unlock(&client_mutex);
 
 	return found_component;
 }
+
+struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
+						   const char *driver_name)
+{
+	struct snd_soc_component *component;
+
+	mutex_lock(&client_mutex);
+	component = snd_soc_lookup_component_nolocked(dev, driver_name);
+	mutex_unlock(&client_mutex);
+
+	return component;
+}
 EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
 
 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
@@ -2853,7 +2863,7 @@ void snd_soc_unregister_component(struct device *dev)
 
 	mutex_lock(&client_mutex);
 	while (1) {
-		component = snd_soc_lookup_component(dev, NULL);
+		component = snd_soc_lookup_component_nolocked(dev, NULL);
 		if (!component)
 			break;
 
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [alsa-devel] Applied "ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component()" to the asoc tree
  2019-11-06  7:05 [alsa-devel] [PATCH] ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component() Kuninori Morimoto
@ 2019-11-06 16:21 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2019-11-06 16:21 UTC (permalink / raw)
  To: Kuninori Morimoto
  Cc: alsa-devel, kernelci.org bot, guillaume.tucker, enric.balletbo, ,
	kernelci.org bot <bot@kernelci.org>,
	khilman@baylibre.com, Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org,
	Mark Brown <broonie@kernel.org>,
	matthew.hart@linaro.org, mgalka@collabora.com,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Takashi Iwai <tiwai@suse.com>,
	tomeu.vizoso@collabora.com

The patch

   ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component()

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5

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 18dd66ea84464a4bc86089276d5f75cadeb94a09 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Date: Wed, 6 Nov 2019 16:05:05 +0900
Subject: [PATCH] ASoC: soc-core: fixup dead-lock at
 snd_soc_unregister_component()

snd_soc_unregister_component() is calling snd_soc_lookup_component()
under mutex_lock(). But, snd_soc_lookup_component() itself is using
mutex_lock(), thus it will be dead-lock.
This patch adds _nolocked version of it, and avoid dead-lock issue.

Fixes: ac6a4dd3e9f0("ASoC: soc-core: use snd_soc_lookup_component() at snd_soc_unregister_component()")
Reported-by: "kernelci.org bot" <bot@kernelci.org>"
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87bltph4da.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index a7ad81ec59db..55014e7ae0d8 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -356,14 +356,13 @@ struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
 }
 EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
 
-struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
-						   const char *driver_name)
+static struct snd_soc_component
+*snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
 {
 	struct snd_soc_component *component;
 	struct snd_soc_component *found_component;
 
 	found_component = NULL;
-	mutex_lock(&client_mutex);
 	for_each_component(component) {
 		if ((dev == component->dev) &&
 		    (!driver_name ||
@@ -373,10 +372,21 @@ struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
 			break;
 		}
 	}
-	mutex_unlock(&client_mutex);
 
 	return found_component;
 }
+
+struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
+						   const char *driver_name)
+{
+	struct snd_soc_component *component;
+
+	mutex_lock(&client_mutex);
+	component = snd_soc_lookup_component_nolocked(dev, driver_name);
+	mutex_unlock(&client_mutex);
+
+	return component;
+}
 EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
 
 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
@@ -2855,7 +2865,7 @@ void snd_soc_unregister_component(struct device *dev)
 
 	mutex_lock(&client_mutex);
 	while (1) {
-		component = snd_soc_lookup_component(dev, NULL);
+		component = snd_soc_lookup_component_nolocked(dev, NULL);
 		if (!component)
 			break;
 
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-06 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-06  7:05 [alsa-devel] [PATCH] ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component() Kuninori Morimoto
2019-11-06 16:21 ` [alsa-devel] Applied "ASoC: soc-core: fixup dead-lock at snd_soc_unregister_component()" to the asoc tree Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).