From patchwork Tue Jan 27 16:13:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 5718671 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CA9189F302 for ; Tue, 27 Jan 2015 16:14:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DAC4620221 for ; Tue, 27 Jan 2015 16:14:39 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 9625D2018E for ; Tue, 27 Jan 2015 16:14:38 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id C61DE2612AC; Tue, 27 Jan 2015 17:14:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 0AD3F2612AC; Tue, 27 Jan 2015 17:13:31 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 79BAB2612AC; Tue, 27 Jan 2015 17:13:29 +0100 (CET) Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 393D92608BC for ; Tue, 27 Jan 2015 17:13:19 +0100 (CET) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DD61AADAF; Tue, 27 Jan 2015 16:13:18 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Tue, 27 Jan 2015 17:13:14 +0100 Message-Id: <1422375197-17293-3-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422375197-17293-1-git-send-email-tiwai@suse.de> References: <1422375197-17293-1-git-send-email-tiwai@suse.de> Cc: Stefan Hajnoczi , Chris Rorvick Subject: [alsa-devel] [PATCH 2/5] ALSA: line6: Clear prev_fbuf and prev_fsize properly X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Clearing prev_fsize in line6_pcm_acquire() is pretty racy. This can be called at any time while the stream is being played. Rather better to clear prev_fbuf and prev_fsize at the proper place like the stream stop for capture, and just after copying the monitor / impulse data inside the spinlock. Signed-off-by: Takashi Iwai --- sound/usb/line6/pcm.c | 8 ++++---- sound/usb/line6/playback.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c index f75825995e24..dedbe24cbf60 100644 --- a/sound/usb/line6/pcm.c +++ b/sound/usb/line6/pcm.c @@ -171,8 +171,6 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels) flags_final = 0; - line6pcm->prev_fbuf = NULL; - if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) { err = line6_alloc_stream_buffer(line6pcm, &line6pcm->in); if (err < 0) @@ -193,7 +191,6 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels) } line6pcm->in.count = 0; - line6pcm->prev_fsize = 0; err = line6_submit_audio_in_all_urbs(line6pcm); if (err < 0) @@ -248,8 +245,11 @@ int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels) flags_new = flags_old & ~channels; } while (cmpxchg(&line6pcm->flags, flags_old, flags_new) != flags_old); - if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_STREAM)) + if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_STREAM)) { line6_unlink_audio_urbs(line6pcm, &line6pcm->in); + line6pcm->prev_fbuf = NULL; + line6pcm->prev_fsize = 0; + } if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) { line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in); diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c index b1d376501616..c1063f1847c3 100644 --- a/sound/usb/line6/playback.c +++ b/sound/usb/line6/playback.c @@ -166,9 +166,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) struct usb_iso_packet_descriptor *fout = &urb_out->iso_frame_desc[i]; - if (line6pcm->flags & LINE6_BITS_CAPTURE_STREAM) - fsize = line6pcm->prev_fsize; - + fsize = line6pcm->prev_fsize; if (fsize == 0) { int n; @@ -263,6 +261,8 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) line6pcm->volume_monitor, bytes_per_frame); } + line6pcm->prev_fbuf = NULL; + line6pcm->prev_fsize = 0; } spin_unlock(&line6pcm->in.lock);