mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geliang Tang <geliangtang@gmail.com>
To: Jens Axboe <axboe@fb.com>, Arnd Bergmann <arnd@arndb.de>,
	Hannes Reinecke <hare@suse.com>,
	Johannes Thumshirn <jthumshirn@suse.de>
Cc: Geliang Tang <geliangtang@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] skd_main: use memdup_user
Date: Sat, 29 Apr 2017 09:45:17 +0800	[thread overview]
Message-ID: <dffefe927f4d442ac8e205b6ce50ee12eae4e991.1493381776.git.geliangtang@gmail.com> (raw)
In-Reply-To: <4db2a0ba17dc68d7bcfbd7d47b0eb22ad9a220c2.1493381463.git.geliangtang@gmail.com>

Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 drivers/block/skd_main.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index 27833e4..6b3cdd2 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -1394,22 +1394,16 @@ static int skd_sg_io_get_and_check_args(struct skd_device *skdev,
 		uint nbytes = sizeof(*iov) * sgp->iovec_count;
 		size_t iov_data_len;
 
-		iov = kmalloc(nbytes, GFP_KERNEL);
-		if (iov == NULL) {
-			pr_debug("%s:%s:%d alloc iovec failed %d\n",
+		iov = memdup_user(sgp->dxferp, nbytes);
+		if (IS_ERR(iov)) {
+			pr_debug("%s:%s:%d memdup_user iovec failed %d %p\n",
 				 skdev->name, __func__, __LINE__,
-				 sgp->iovec_count);
-			return -ENOMEM;
+				 sgp->iovec_count, sgp->dxferp);
+			return PTR_ERR(iov);
 		}
 		sksgio->iov = iov;
 		sksgio->iovcnt = sgp->iovec_count;
 
-		if (copy_from_user(iov, sgp->dxferp, nbytes)) {
-			pr_debug("%s:%s:%d copy_from_user iovec failed %p\n",
-				 skdev->name, __func__, __LINE__, sgp->dxferp);
-			return -EFAULT;
-		}
-
 		/*
 		 * Sum up the vecs, making sure they don't overflow
 		 */
-- 
2.9.3

  parent reply	other threads:[~2017-04-29  1:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-29  1:45 [PATCH] cciss: " Geliang Tang
2017-04-29  1:45 ` [PATCH] floppy: " Geliang Tang
2017-04-29  1:45 ` [PATCH] powerpc/nvram: " Geliang Tang
2017-06-28  0:08   ` Kees Cook
2017-04-29  1:45 ` [PATCH] powerpc/powernv: " Geliang Tang
2017-07-27 12:37   ` Michael Ellerman
2017-04-29  1:45 ` [PATCH] powerpc/pseries: use memdup_user_nul Geliang Tang
2017-07-27 12:37   ` Michael Ellerman
2017-04-29  1:45 ` [PATCH] pstore: use memdup_user Geliang Tang
2017-06-28  0:07   ` Kees Cook
2017-04-29  1:45 ` Geliang Tang [this message]
2017-04-29  1:45 ` [PATCH] staging: comedi: " Geliang Tang
2017-04-29  1:53   ` Joe Perches
2017-04-29  5:17     ` Greg Kroah-Hartman

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=dffefe927f4d442ac8e205b6ce50ee12eae4e991.1493381776.git.geliangtang@gmail.com \
    --to=geliangtang@gmail.com \
    --cc=arnd@arndb.de \
    --cc=axboe@fb.com \
    --cc=hare@suse.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome