[PATCH] skd_main: use memdup_user

From: Geliang Tang
Date: Fri Apr 28 2017 - 21:47:43 EST


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

Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx>
---
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