From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756226Ab3KLQ35 (ORCPT ); Tue, 12 Nov 2013 11:29:57 -0500 Received: from cantor2.suse.de ([195.135.220.15]:38966 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755148Ab3KLQ3x (ORCPT ); Tue, 12 Nov 2013 11:29:53 -0500 Date: Tue, 12 Nov 2013 17:29:51 +0100 Message-ID: From: Takashi Iwai To: "Oskar Schirmer" Cc: "Jaroslav Kysela" , linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, "Andrew Morton" Subject: Re: [PATCH] ALSA: pcm: retrieve true appl_ptr where stream was unlocked In-Reply-To: <1384272857-24473-1-git-send-email-oskar@scara.com> References: <1384272857-24473-1-git-send-email-oskar@scara.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At 12 Nov 2013 16:14:17 +0000, Oskar Schirmer wrote: > > Calculated for data transfer, the local variable appl_ptr is reused, > changed and written back later, though the lock was not held during > the transfer earlier. Admitted, destiny of the lock is not obvious > at all, but this looks much like a race condition candidate, so make > sure to have some original appl_ptr value to work on. No, appl_ptr doesn't have to be re-read at that point. Otherwise the value will become inconsistent. This is the write operation to a stream and it's exclusive. The lock is needed to protect the PCM state change (e.g. stopped from an irq handler). thanks, Takashi > > Two occurences. > > Signed-off-by: Oskar Schirmer > --- > sound/core/pcm_lib.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c > index 6e03b46..47e836a 100644 > --- a/sound/core/pcm_lib.c > +++ b/sound/core/pcm_lib.c > @@ -2051,6 +2051,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream, > default: > break; > } > + appl_ptr = runtime->control->appl_ptr; > appl_ptr += frames; > if (appl_ptr >= runtime->boundary) > appl_ptr -= runtime->boundary; > @@ -2283,6 +2284,7 @@ static snd_pcm_sframes_t snd_pcm_lib_read1(struct snd_pcm_substream *substream, > default: > break; > } > + appl_ptr = runtime->control->appl_ptr; > appl_ptr += frames; > if (appl_ptr >= runtime->boundary) > appl_ptr -= runtime->boundary; > -- > 1.7.9.5 >