ALSA: compress: Use memdup_user() rather than duplicating its implementation
authorMarkus Elfring <elfring@users.sourceforge.net>
Sun, 21 Aug 2016 19:02:06 +0000 (21:02 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 22 Aug 2016 12:04:18 +0000 (14:04 +0200)
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Acked-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/compress_offload.c

index 2c498488af6c5aebe12ec4a2cd7b432076b788af..583d4076903a62ac3a920399dbd3b52ac57e0e3f 100644 (file)
@@ -553,13 +553,9 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
                 * we should allow parameter change only when stream has been
                 * opened not in other cases
                 */
-               params = kmalloc(sizeof(*params), GFP_KERNEL);
-               if (!params)
-                       return -ENOMEM;
-               if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
-                       retval = -EFAULT;
-                       goto out;
-               }
+               params = memdup_user((void __user *)arg, sizeof(*params));
+               if (IS_ERR(params))
+                       return PTR_ERR(params);
 
                retval = snd_compress_check_input(params);
                if (retval)