[PATCH 2/2] ALSA: pcm: Use stream lock in snd_pcm_detach_substream()

paulhsia
2019-11-12T17:17:35Z

Since snd_pcm_detach_substream modifies the input substream, the
function should use stream lock to protect the modification section.

Signed-off-by: paulhsia <paulhsia@chromium.org>
---
sound/core/pcm.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 9a72d641743d..06da9cb8984a 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -980,8 +980,12 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime;

- if (PCM_RUNTIME_CHECK(substream))
+ if (snd_BUG_ON(!substream))
return;
+
+ snd_pcm_stream_lock_irq(substream);
+ if (PCM_RUNTIME_CHECK(substream))
+ goto unlock;
runtime = substream->runtime;
if (runtime->private_free != NULL)
runtime->private_free(runtime);
@@ -1000,6 +1004,8 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
put_pid(substream->pid);
substream->pid = NULL;
substream->pstr->substream_opened--;
+ unlock:
+ snd_pcm_stream_unlock_irq(substream);
}

static ssize_t show_pcm_class(struct device *dev,
--
2.24.0.rc1.363.gb1bccd3e3d-goog