aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-01-23 10:25:03 -0500
committerTakashi Iwai <tiwai@suse.de>2015-01-28 01:21:39 -0500
commite90576c5955c83cd7e8c191b47f70d1946015041 (patch)
treead2fe83b3cf4f2da9ab89bb44c81d66fb37a5a5b /sound/usb
parentccaac9ed79c6051733f781a1cd639d488696f512 (diff)
ALSA: line6: Consolidate PCM stream buffer allocation and free
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>
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/line6/capture.c6
-rw-r--r--sound/usb/line6/capture.h1
-rw-r--r--sound/usb/line6/pcm.c53
-rw-r--r--sound/usb/line6/playback.c6
-rw-r--r--sound/usb/line6/playback.h1
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)
141 } 141 }
142} 142}
143 143
144void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm)
145{
146 kfree(line6pcm->in.buffer);
147 line6pcm->in.buffer = NULL;
148}
149
150/* 144/*
151 * Callback for completed capture URB. 145 * Callback for completed capture URB.
152 */ 146 */
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,
24extern void line6_capture_check_period(struct snd_line6_pcm *line6pcm, 24extern void line6_capture_check_period(struct snd_line6_pcm *line6pcm,
25 int length); 25 int length);
26extern int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm); 26extern int line6_create_audio_in_urbs(struct snd_line6_pcm *line6pcm);
27extern void line6_free_capture_buffer(struct snd_line6_pcm *line6pcm);
28extern int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm); 27extern int line6_submit_audio_in_all_urbs(struct snd_line6_pcm *line6pcm);
29extern int snd_line6_capture_trigger(struct snd_line6_pcm *line6pcm, int cmd); 28extern int snd_line6_capture_trigger(struct snd_line6_pcm *line6pcm, int cmd);
30 29
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,
132 "timeout: still %d active urbs..\n", alive); 132 "timeout: still %d active urbs..\n", alive);
133} 133}
134 134
135static int line6_alloc_stream_buffer(struct snd_line6_pcm *line6pcm,
136 struct line6_pcm_stream *pcms)
137{
138 /* Invoked multiple times in a row so allocate once only */
139 if (pcms->buffer)
140 return 0;
141
142 pcms->buffer = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
143 line6pcm->max_packet_size, GFP_KERNEL);
144 if (!pcms->buffer)
145 return -ENOMEM;
146 return 0;
147}
148
149static void line6_free_stream_buffer(struct snd_line6_pcm *line6pcm,
150 struct line6_pcm_stream *pcms)
151{
152 kfree(pcms->buffer);
153 pcms->buffer = NULL;
154}
155
135static bool test_flags(unsigned long flags0, unsigned long flags1, 156static bool test_flags(unsigned long flags0, unsigned long flags1,
136 unsigned long mask) 157 unsigned long mask)
137{ 158{
@@ -153,17 +174,9 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
153 line6pcm->prev_fbuf = NULL; 174 line6pcm->prev_fbuf = NULL;
154 175
155 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) { 176 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) {
156 /* Invoked multiple times in a row so allocate once only */ 177 err = line6_alloc_stream_buffer(line6pcm, &line6pcm->in);
157 if (!line6pcm->in.buffer) { 178 if (err < 0)
158 line6pcm->in.buffer = 179 goto pcm_acquire_error;
159 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
160 line6pcm->max_packet_size, GFP_KERNEL);
161 if (!line6pcm->in.buffer) {
162 err = -ENOMEM;
163 goto pcm_acquire_error;
164 }
165 }
166
167 flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER; 180 flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER;
168 } 181 }
169 182
@@ -190,17 +203,9 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
190 } 203 }
191 204
192 if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) { 205 if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) {
193 /* Invoked multiple times in a row so allocate once only */ 206 err = line6_alloc_stream_buffer(line6pcm, &line6pcm->out);
194 if (!line6pcm->out.buffer) { 207 if (err < 0)
195 line6pcm->out.buffer = 208 goto pcm_acquire_error;
196 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
197 line6pcm->max_packet_size, GFP_KERNEL);
198 if (!line6pcm->out.buffer) {
199 err = -ENOMEM;
200 goto pcm_acquire_error;
201 }
202 }
203
204 flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER; 209 flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER;
205 } 210 }
206 211
@@ -248,7 +253,7 @@ int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels)
248 253
249 if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) { 254 if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) {
250 line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in); 255 line6_wait_clear_audio_urbs(line6pcm, &line6pcm->in);
251 line6_free_capture_buffer(line6pcm); 256 line6_free_stream_buffer(line6pcm, &line6pcm->in);
252 } 257 }
253 258
254 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_STREAM)) 259 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)
256 261
257 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) { 262 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) {
258 line6_wait_clear_audio_urbs(line6pcm, &line6pcm->out); 263 line6_wait_clear_audio_urbs(line6pcm, &line6pcm->out);
259 line6_free_playback_buffer(line6pcm); 264 line6_free_stream_buffer(line6pcm, &line6pcm->out);
260 } 265 }
261 266
262 return 0; 267 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)
290 return 0; 290 return 0;
291} 291}
292 292
293void line6_free_playback_buffer(struct snd_line6_pcm *line6pcm)
294{
295 kfree(line6pcm->out.buffer);
296 line6pcm->out.buffer = NULL;
297}
298
299/* 293/*
300 Callback for completed playback URB. 294 Callback for completed playback URB.
301*/ 295*/
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 @@
30extern struct snd_pcm_ops snd_line6_playback_ops; 30extern struct snd_pcm_ops snd_line6_playback_ops;
31 31
32extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm); 32extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
33extern void line6_free_playback_buffer(struct snd_line6_pcm *line6pcm);
34extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm); 33extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
35extern int snd_line6_playback_trigger(struct snd_line6_pcm *line6pcm, int cmd); 34extern int snd_line6_playback_trigger(struct snd_line6_pcm *line6pcm, int cmd);
36 35