[Line6linux-devel] [PATCH 1/5] staging: line6: fix memory leak in .hw_params()
Status: Pre-Alpha
Brought to you by:
mgrabner
From: <ste...@gm...> - 2011-12-03 14:17:15
|
From: Stefan Hajnoczi <ste...@gm...> 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 <ste...@gm...> --- 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 |