rapidio/rio_cm: use memdup_user() instead of duplicating code
authorAlexandre Bounine <[email protected]>
Tue, 11 Oct 2016 20:53:49 +0000 (13:53 -0700)
committerLinus Torvalds <[email protected]>
Tue, 11 Oct 2016 22:06:32 +0000 (15:06 -0700)
Fix coccinelle warning about duplicating existing memdup_user function.

Link: http://lkml.kernel.org/r/[email protected]
Link: https://lkml.org/lkml/2016/8/11/29
Signed-off-by: Alexandre Bounine <[email protected]>
Reported-by: kbuild test robot <[email protected]>
Cc: Matt Porter <[email protected]>
Cc: Andre van Herk <[email protected]>
Cc: Barry Wood <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/rapidio/rio_cm.c

index cebc296463ad17efe25fc6fa8b4bde593f1fdff3..bad0e0ea4f3059e51b6cfaffc78c859c1be3aecb 100644 (file)
@@ -1841,24 +1841,19 @@ static int cm_chan_msg_send(void __user *arg)
 {
        struct rio_cm_msg msg;
        void *buf;
-       int ret = 0;
+       int ret;
 
        if (copy_from_user(&msg, arg, sizeof(msg)))
                return -EFAULT;
        if (msg.size > RIO_MAX_MSG_SIZE)
                return -EINVAL;
 
-       buf = kmalloc(msg.size, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       if (copy_from_user(buf, (void __user *)(uintptr_t)msg.msg, msg.size)) {
-               ret = -EFAULT;
-               goto out;
-       }
+       buf = memdup_user((void __user *)(uintptr_t)msg.msg, msg.size);
+       if (IS_ERR(buf))
+               return PTR_ERR(buf);
 
        ret = riocm_ch_send(msg.ch_num, buf, msg.size);
-out:
+
        kfree(buf);
        return ret;
 }