[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <s5hwq4jqewi.wl-tiwai@suse.de>
Date: Mon, 19 Jan 2015 10:49:01 +0100
From: Takashi Iwai <tiwai@...e.de>
To: Jiri Slaby <jslaby@...e.cz>
Cc: linux-kernel@...r.kernel.org, Jaroslav Kysela <perex@...ex.cz>,
alsa-devel@...a-project.org
Subject: Re: [PATCH 3/3] sound: dummy, avoid races with timer
At Mon, 19 Jan 2015 10:42:56 +0100,
Jiri Slaby wrote:
>
> There is a race between timer and process contexts. Process context
> does not disable irqs, so when a timer ticks inside process' critical
> section, the system can deadlock. Fix this by a traditional _irqsave
> variant of spin_lock.
>
> Signed-off-by: Jiri Slaby <jslaby@...e.cz>
> Cc: Jaroslav Kysela <perex@...ex.cz>
> Cc: Takashi Iwai <tiwai@...e.de>
> Cc: alsa-devel@...a-project.org
> ---
> sound/drivers/dummy.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
> index 6d6bf4093583..18a7cfc99078 100644
> --- a/sound/drivers/dummy.c
> +++ b/sound/drivers/dummy.c
> @@ -271,10 +271,13 @@ static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm)
> static int dummy_systimer_start(struct snd_pcm_substream *substream)
> {
> struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
> - spin_lock(&dpcm->lock);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&dpcm->lock, flags);
> dpcm->base_time = jiffies;
> dummy_systimer_rearm(dpcm);
> - spin_unlock(&dpcm->lock);
> + spin_unlock_irqrestore(&dpcm->lock, flags);
> +
This looks correct, but...
> return 0;
> }
>
> @@ -322,12 +325,14 @@ static snd_pcm_uframes_t
> dummy_systimer_pointer(struct snd_pcm_substream *substream)
> {
> struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
> + unsigned long flags;
> snd_pcm_uframes_t pos;
>
> - spin_lock(&dpcm->lock);
> + spin_lock_irqsave(&dpcm->lock, flags);
> dummy_systimer_update(dpcm);
> pos = dpcm->frac_pos / HZ;
> - spin_unlock(&dpcm->lock);
> + spin_unlock_irqrestore(&dpcm->lock, flags);
> +
This chunk is superfluous. The pointer callback is guaranteed to be
called in the irq-disabled context.
thanks,
Takashi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists