[2/3] echoaudio: Prevent races in calls to set_audio_format()
diff mbox series

Message ID 20200616131743.4793-2-mark@xwax.org
State New
Headers show
Series
  • [1/3] echoaudio: Race conditions around "opencount"
Related show

Commit Message

Mark Hills June 16, 2020, 1:17 p.m. UTC
The function uses chip->comm_page which needs locking against
other use at the same time.

Signed-off-by: Mark Hills <mark@xwax.org>
---
 sound/pci/echoaudio/echoaudio.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Takashi Iwai June 16, 2020, 1:24 p.m. UTC | #1
On Tue, 16 Jun 2020 15:17:42 +0200,
Mark Hills wrote:
> 
> The function uses chip->comm_page which needs locking against
> other use at the same time.
> 
> Signed-off-by: Mark Hills <mark@xwax.org>
> ---
>  sound/pci/echoaudio/echoaudio.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
> index 82a49dfd2384..8cf08988959f 100644
> --- a/sound/pci/echoaudio/echoaudio.c
> +++ b/sound/pci/echoaudio/echoaudio.c
> @@ -711,9 +711,22 @@ static int pcm_prepare(struct snd_pcm_substream *substream)
>  
>  	if (snd_BUG_ON(pipe_index >= px_num(chip)))
>  		return -EINVAL;
> -	if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
> +
> +	/*
> +	 * We passed checks we can do independently; now take
> +	 * exclusive control
> +	 */
> +
> +	spin_lock(&chip->lock);

You need spin_lock_irq() and spin_unlock_irq(), as the prepare
callback in in sleepable context.


thanks,

Takashi

Patch
diff mbox series

diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 82a49dfd2384..8cf08988959f 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -711,9 +711,22 @@  static int pcm_prepare(struct snd_pcm_substream *substream)
 
 	if (snd_BUG_ON(pipe_index >= px_num(chip)))
 		return -EINVAL;
-	if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index)))
+
+	/*
+	 * We passed checks we can do independently; now take
+	 * exclusive control
+	 */
+
+	spin_lock(&chip->lock);
+
+	if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index))) {
+		spin_unlock(&chip->lock);
 		return -EINVAL;
+	}
+
 	set_audio_format(chip, pipe_index, &format);
+	spin_unlock(&chip->lock);
+
 	return 0;
 }