All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Cc: Stefan Hajnoczi <stefanha@gmail.com>, Chris Rorvick <chris@rorvick.com>
Subject: [PATCH 14/16] ALSA: line6: Consolidate PCM stream buffer allocation and free
Date: Fri, 23 Jan 2015 18:13:21 +0100	[thread overview]
Message-ID: <1422033203-23254-15-git-send-email-tiwai@suse.de> (raw)
In-Reply-To: <1422033203-23254-1-git-send-email-tiwai@suse.de>

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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/line6/capture.c  |  6 ------
 sound/usb/line6/capture.h  |  1 -
 sound/usb/line6/pcm.c      | 53 +++++++++++++++++++++++++---------------------
 sound/usb/line6/playback.c |  6 ------
 sound/usb/line6/playback.h |  1 -
 5 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c
index 1d477d7a42fb..47cfcc2ab387 100644
--- a/sound/usb/line6/capture.c
+++ b/sound/usb/line6/capture.c
@@ -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.
  */
diff --git a/sound/usb/line6/capture.h b/sound/usb/line6/capture.h
index 3cc71bc70b21..db062e7200a6 100644
--- a/sound/usb/line6/capture.h
+++ b/sound/usb/line6/capture.h
@@ -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);
 
diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c
index 4152d92105b1..f75825995e24 100644
--- a/sound/usb/line6/pcm.c
+++ b/sound/usb/line6/pcm.c
@@ -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;
diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c
index 3820ed08b342..750d91dced57 100644
--- a/sound/usb/line6/playback.c
+++ b/sound/usb/line6/playback.c
@@ -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.
 */
diff --git a/sound/usb/line6/playback.h b/sound/usb/line6/playback.h
index 52a278353d3b..f6a9e18f87b6 100644
--- a/sound/usb/line6/playback.h
+++ b/sound/usb/line6/playback.h
@@ -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);
 
-- 
2.2.2

  parent reply	other threads:[~2015-01-23 17:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 17:13 [PATCH 00/16] Yet more cleanups of line6 drivers Takashi Iwai
2015-01-23 17:13 ` [PATCH 01/16] ALSA: line6: Minor refactoring Takashi Iwai
2015-01-23 17:13 ` [PATCH 02/16] ALSA: line6: Fix memory leak at probe error path Takashi Iwai
2015-01-25  8:06   ` Chris Rorvick
2015-01-26 12:47     ` Takashi Iwai
2015-01-23 17:13 ` [PATCH 03/16] ALSA: line6: Remove unused line6_nop_read() Takashi Iwai
2015-01-23 17:13 ` [PATCH 04/16] ALSA: line6: Reduce superfluous spinlock in midi.c Takashi Iwai
2015-01-23 17:13 ` [PATCH 05/16] ALSA: line6: Fix missing error handling in line6_pcm_acquire() Takashi Iwai
2015-01-23 17:13 ` [PATCH 06/16] ALSA: line6: Use logical OR Takashi Iwai
2015-01-23 17:13 ` [PATCH 07/16] ALSA: line6: Fix the error recovery in line6_pcm_acquire() Takashi Iwai
2015-01-23 17:13 ` [PATCH 08/16] ALSA: line6: Drop superfluous spinlock for trigger Takashi Iwai
2015-01-27  6:22   ` Chris Rorvick
2015-01-27 10:27     ` Takashi Iwai
2015-01-27 12:48       ` Chris Rorvick
2015-01-27 16:10         ` Takashi Iwai
2015-01-28  6:03           ` Chris Rorvick
2015-01-28  6:26             ` Takashi Iwai
2015-01-28 14:02               ` Chris Rorvick
2015-01-23 17:13 ` [PATCH 09/16] ALSA: line6: Use incremental loop Takashi Iwai
2015-01-23 17:13 ` [PATCH 10/16] ALSA: line6: Drop voodoo workarounds Takashi Iwai
2015-01-27  3:58   ` Chris Rorvick
2015-01-23 17:13 ` [PATCH 11/16] ALSA: line6: Rearrange PCM structure Takashi Iwai
2015-01-23 17:13 ` [PATCH 12/16] ALSA: line6: Consolidate URB unlink and sync helpers Takashi Iwai
2015-01-23 17:13 ` [PATCH 13/16] ALSA: line6: Use dev_err() Takashi Iwai
2015-01-23 17:13 ` Takashi Iwai [this message]
2015-01-23 17:13 ` [PATCH 15/16] ALSA: line6: Do clipping in volume / monitor manipulations Takashi Iwai
2015-01-23 17:13 ` [PATCH 16/16] ALSA: line6: Skip volume manipulation during silence copying Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422033203-23254-15-git-send-email-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=chris@rorvick.com \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.