From: Takashi Iwai Date: Thu, 29 Nov 2018 07:02:49 +0000 (+0100) Subject: ALSA: pcm: Call snd_pcm_unlink() conditionally at closing X-Git-Tag: v3.18.129~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d26525be5f2aa25e596fb293b7d2027835ebf214;p=profile%2Fwearable%2Fplatform%2Fkernel%2Flinux-3.18-exynos7270.git ALSA: pcm: Call snd_pcm_unlink() conditionally at closing commit b51abed8355e5556886623b2772fa6b7598d2282 upstream. Currently the PCM core calls snd_pcm_unlink() always unconditionally at closing a stream. However, since snd_pcm_unlink() invokes the global rwsem down, the lock can be easily contended. More badly, when a thread runs in a high priority RT-FIFO, it may stall at spinning. Basically the call of snd_pcm_unlink() is required only for the linked streams that are already rare occasion. For normal use cases, this code path is fairly superfluous. As an optimization (and also as a workaround for the RT problem above in normal situations without linked streams), this patch adds a check before calling snd_pcm_unlink() and calls it only when needed. Reported-by: Chanho Min Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index e2d78f8..7b61399 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2193,7 +2193,8 @@ int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) static void pcm_release_private(struct snd_pcm_substream *substream) { - snd_pcm_unlink(substream); + if (snd_pcm_stream_linked(substream)) + snd_pcm_unlink(substream); } void snd_pcm_release_substream(struct snd_pcm_substream *substream)