From: Stefan Hajnoczi <[email protected]>

The .hw_params() pcm callback can be invoked multiple times in a row.
Ensure that the URB data buffer is only allocated once.

Signed-off-by: Stefan Hajnoczi <[email protected]>
---
 capture.c  |    7 +++++--
 playback.c |    7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/capture.c b/capture.c
index d9da7ed..c7e3bfa 100644
--- a/capture.c
+++ b/capture.c
@@ -320,8 +320,11 @@ static int snd_line6_capture_hw_params(struct 
snd_pcm_substream *substream,
        }
        /* -- [FD] end */
 
-       line6pcm->buffer_in = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
-                                     line6pcm->max_packet_size, GFP_KERNEL);
+       /* We may be invoked multiple times in a row so allocate once only */
+       if (!line6pcm->buffer_in)
+               line6pcm->buffer_in =
+                       kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
+                               line6pcm->max_packet_size, GFP_KERNEL);
 
        if (!line6pcm->buffer_in) {
                dev_err(line6pcm->line6->ifcdev,
diff --git a/playback.c b/playback.c
index b344527..c39d1f0 100644
--- a/playback.c
+++ b/playback.c
@@ -470,8 +470,11 @@ static int snd_line6_playback_hw_params(struct 
snd_pcm_substream *substream,
        }
        /* -- [FD] end */
 
-       line6pcm->buffer_out = kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
-                                      line6pcm->max_packet_size, GFP_KERNEL);
+       /* We may be invoked multiple times in a row so allocate once only */
+       if (!line6pcm->buffer_out)
+               line6pcm->buffer_out =
+                       kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
+                               line6pcm->max_packet_size, GFP_KERNEL);
 
        if (!line6pcm->buffer_out) {
                dev_err(line6pcm->line6->ifcdev,
-- 
1.7.7.3


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Line6linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/line6linux-devel

Reply via email to