ALSA: line6: Clear prev_fbuf and prev_fsize properly
authorTakashi Iwai <tiwai@suse.de>
Tue, 27 Jan 2015 15:17:26 +0000 (16:17 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 28 Jan 2015 06:22:30 +0000 (07:22 +0100)
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.

Tested-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/line6/pcm.c
sound/usb/line6/playback.c

index f75825995e24a5769b4a042406692456006b4764..dedbe24cbf6073ba8f8b869a4b02d5d70a26a4cf 100644 (file)
@@ -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);
index b4a26d0c82671587c659828de03b4726de7d4375..242265929145909805a381050e1050ef75a3f8f3 100644 (file)
@@ -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);