summaryrefslogtreecommitdiff
path: root/sound/core
diff options
context:
space:
mode:
authorJesper Juhl <jj@chaosbits.net>2012-01-23 21:02:57 +0100
committerTakashi Iwai <tiwai@suse.de>2012-01-24 15:29:32 +0100
commit769fab2a41da4bd3c59eee38f47d6d5405738fe0 (patch)
tree615fc66dc9e534bc2318d4120d3506f85dbeb1e8 /sound/core
parent4d20bb1d5fe1afbdbff951c06cd3d3654fa5ceed (diff)
ALSA: Fix memory leak on error in snd_compr_set_params()
If copy_from_user() does not return 0 we'll leak the memory we allocated for 'params' when that variable goes out of scope. Also a small CodingStyle cleanup: Use braces on both branches of if/else when one branch needs it. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Acked-by: Vinod Koul <vinod.koul@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/compress_offload.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index dac3633507c9..a68aed7fce02 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -441,19 +441,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
params = kmalloc(sizeof(*params), GFP_KERNEL);
if (!params)
return -ENOMEM;
- if (copy_from_user(params, (void __user *)arg, sizeof(*params)))
- return -EFAULT;
+ if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
+ retval = -EFAULT;
+ goto out;
+ }
retval = snd_compr_allocate_buffer(stream, params);
if (retval) {
- kfree(params);
- return -ENOMEM;
+ retval = -ENOMEM;
+ goto out;
}
retval = stream->ops->set_params(stream, params);
if (retval)
goto out;
stream->runtime->state = SNDRV_PCM_STATE_SETUP;
- } else
+ } else {
return -EPERM;
+ }
out:
kfree(params);
return retval;