coda: use vmemdup_user to replace the open code
authorJing Yangyang <jing.yangyang@zte.com.cn>
Tue, 9 Nov 2021 02:34:52 +0000 (18:34 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 Nov 2021 18:02:51 +0000 (10:02 -0800)
vmemdup_user is better than duplicating its implementation, So just
replace the open code.

  fs/coda/psdev.c:125:10-18:WARNING:opportunity for vmemdup_user

The issue is detected with the help of Coccinelle.

Link: https://lkml.kernel.org/r/20210908140308.18491-9-jaharkes@cs.cmu.edu
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Jing Yangyang <jing.yangyang@zte.com.cn>
Signed-off-by: Jan Harkes <jaharkes@cs.cmu.edu>
Cc: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Xin Tan <tanxin.ctf@gmail.com>
Cc: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/coda/psdev.c

index 240669f..7e23cb2 100644 (file)
@@ -122,14 +122,10 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
                                hdr.opcode, hdr.unique);
                        nbytes = size;
                }
-               dcbuf = kvmalloc(nbytes, GFP_KERNEL);
-               if (!dcbuf) {
-                       retval = -ENOMEM;
-                       goto out;
-               }
-               if (copy_from_user(dcbuf, buf, nbytes)) {
-                       kvfree(dcbuf);
-                       retval = -EFAULT;
+
+               dcbuf = vmemdup_user(buf, nbytes);
+               if (IS_ERR(dcbuf)) {
+                       retval = PTR_ERR(dcbuf);
                        goto out;
                }