Skip to content

Commit

Permalink
coda: use vmemdup_user to replace the open code
Browse files Browse the repository at this point in the history
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/[email protected]
Reported-by: Zeal Robot <[email protected]>
Signed-off-by: Jing Yangyang <[email protected]>
Signed-off-by: Jan Harkes <[email protected]>
Cc: Alex Shi <[email protected]>
Cc: Xin Tan <[email protected]>
Cc: Xiyu Yang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Jing Yangyang authored and torvalds committed Nov 9, 2021
1 parent 1077c28 commit 118b7ee
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions fs/coda/psdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 118b7ee

Please sign in to comment.