All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Harkes <jaharkes@cs.cmu.edu>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Harkes <jaharkes@cs.cmu.edu>,
	linux-fsdevel@vger.kernel.org,
	Jing Yangyang <jing.yangyang@zte.com.cn>,
	Zeal Robot <zealci@zte.com.cn>
Subject: [PATCH 8/9] coda: Use vmemdup_user to replace the open code
Date: Wed,  8 Sep 2021 10:03:07 -0400	[thread overview]
Message-ID: <20210908140308.18491-9-jaharkes@cs.cmu.edu> (raw)
In-Reply-To: <20210908140308.18491-1-jaharkes@cs.cmu.edu>

From: Jing Yangyang <jing.yangyang@zte.com.cn>

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.

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>
---
 fs/coda/psdev.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index 240669f51eac..7e23cb22d394 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -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;
 		}
 
-- 
2.25.1


  parent reply	other threads:[~2021-09-08 14:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08 14:02 [PATCH 0/9] Coda updates for -next Jan Harkes
2021-09-08 14:03 ` [PATCH 1/9] coda: Avoid NULL pointer dereference from a bad inode Jan Harkes
2021-09-08 14:03 ` [PATCH 2/9] coda: Check for async upcall request using local state Jan Harkes
2021-09-08 14:03 ` [PATCH 3/9] coda: remove err which no one care Jan Harkes
2021-09-08 14:03 ` [PATCH 4/9] coda: Avoid flagging NULL inodes Jan Harkes
2021-09-08 14:03 ` [PATCH 5/9] coda: Avoid hidden code duplication in rename Jan Harkes
2021-09-08 14:03 ` [PATCH 6/9] coda: Avoid doing bad things on inode type changes during revalidation Jan Harkes
2021-09-08 14:03 ` [PATCH 7/9] coda: Convert from atomic_t to refcount_t on coda_vm_ops->refcnt Jan Harkes
2021-09-08 14:03 ` Jan Harkes [this message]
2021-09-08 14:03 ` [PATCH 9/9] coda: Bump module version to 7.2 Jan Harkes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210908140308.18491-9-jaharkes@cs.cmu.edu \
    --to=jaharkes@cs.cmu.edu \
    --cc=akpm@linux-foundation.org \
    --cc=jing.yangyang@zte.com.cn \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=zealci@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.