ALSA: line6: Consolidate PCM stream buffer allocation and free
authorTakashi Iwai <tiwai@suse.de>
Fri, 23 Jan 2015 15:25:03 +0000 (16:25 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 28 Jan 2015 06:21:39 +0000 (07:21 +0100)
The PCM stream buffer allocation and free are identical for both
playback and capture streams.  Provide single helper functions.
These are used only in pcm.c, thus they can be even static.

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

index 1d477d7a42fbfd74f36cc807b59937c18b8f9dc9..47cfcc2ab38797797e8d9ebf72b657fd117d54d0 100644 (file)
@@ -141,12 +141,6 @@ void line6_capture_check_period(struct snd_line6_pcm *line6pcm, int length)
        }
 }
 
-void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm)
-{
-       kfree(line6pcm->in.buffer);
-       line6pcm->in.buffer = NULL;
-}
-
 /*
  * Callback for completed capture URB.
  */
index 3cc71bc70b21cced03d3e79bd7dab40d1beb73c0..db062e7200a650dce7076cb7ebbad43a3ac7eaba 100644 (file)
@@ -24,7 +24,6 @@ extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
 extern void line6_capture_check_period(struct snd_line6_pcm *line6pcm,
                                       int length);
 extern int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm);
-extern void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm);
 extern int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm);
 extern int snd_line6_capture_trigger(struct snd_line6_pcm *line6pcm, int cmd);
 
index 4152d92105b15a85fbf3249b695eb7c043e1937f..f75825995e24a5769b4a042406692456006b4764 100644 (file)
@@ -132,6 +132,27 @@ static void line6_wait_clear_audio_urbs(struct snd_line6_pcm *line6pcm,
                        "timeout: still %d active urbs..\n", alive);
 }
 
+static int line6_alloc_stream_buffer(struct snd_line6_pcm *line6pcm,
+                                    struct line6_pcm_stream *pcms)
+{
+       /* Invoked multiple times in a row so allocate once only */
+       if (pcms->buffer)
+               return 0;
+
+       pcms->buffer = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
+                              line6pcm->max_packet_size, GFP_KERNEL);
+       if (!pcms->buffer)
+               return -ENOMEM;
+       return 0;
+}
+
+static void line6_free_stream_buffer(struct snd_line6_pcm *line6pcm,
+                                    struct line6_pcm_stream *pcms)
+{
+       kfree(pcms->buffer);
+       pcms->buffer = NULL;
+}
+
 static bool test_flags(unsigned long flags0, unsigned long flags1,
                       unsigned long mask)
 {
@@ -153,17 +174,9 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
        line6pcm->prev_fbuf = NULL;
 
        if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) {
-               /* Invoked multiple times in a row so allocate once only */
-               if (!line6pcm->in.buffer) {
-                       line6pcm->in.buffer =
-                               kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
-                                       line6pcm->max_packet_size, GFP_KERNEL);
-                       if (!line6pcm->in.buffer) {
-                               err = -ENOMEM;
-                               goto pcm_acquire_error;
-                       }
-               }
-
+               err = line6_alloc_stream_buffer(line6pcm, &line6pcm->in);
+               if (err < 0)
+                       goto pcm_acquire_error;
                flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER;
        }
 
@@ -190,17 +203,9 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
        }
 
        if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) {
-               /* Invoked multiple times in a row so allocate once only */
-               if (!line6pcm->out.buffer) {
-                       line6pcm->out.buffer =
-                               kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
-                                       line6pcm->max_packet_size, GFP_KERNEL);
-                       if (!line6pcm->out.buffer) {
-                               err = -ENOMEM;
-                               goto pcm_acquire_error;
-                       }
-               }
-
+               err = line6_alloc_stream_buffer(line6pcm, &line6pcm->out);
+               if (err < 0)
+                       goto pcm_acquire_error;
                flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER;
        }
 
@@ -248,7 +253,7 @@ int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels)
 
        if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) {
                line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in);
-               line6_free_capture_buffer(line6pcm);
+               line6_free_stream_buffer(line6pcm, &line6pcm->in);
        }
 
        if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_STREAM))
@@ -256,7 +261,7 @@ int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels)
 
        if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) {
                line6_wait_clear_audio_urbs(line6pcm, &line6pcm->out);
-               line6_free_playback_buffer(line6pcm);
+               line6_free_stream_buffer(line6pcm, &line6pcm->out);
        }
 
        return 0;
index 3820ed08b3420a4253fd9e800eee2401bc5836ac..750d91dced576ec26f146c0a184dd50bffb41545 100644 (file)
@@ -290,12 +290,6 @@ int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm)
        return 0;
 }
 
-void line6_free_playback_buffer(struct snd_line6_pcm *line6pcm)
-{
-       kfree(line6pcm->out.buffer);
-       line6pcm->out.buffer = NULL;
-}
-
 /*
        Callback for completed playback URB.
 */
index 52a278353d3bc86b2ab3d77fc288664277dffdc1..f6a9e18f87b6f01226fffcac81df0af1508453df 100644 (file)
@@ -30,7 +30,6 @@
 extern struct snd_pcm_ops snd_line6_playback_ops;
 
 extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
-extern void line6_free_playback_buffer(struct snd_line6_pcm *line6pcm);
 extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
 extern int snd_line6_playback_trigger(struct snd_line6_pcm *line6pcm, int cmd);