sg_start_req(): use import_iovec()
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 22 Mar 2015 00:25:30 +0000 (20:25 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 12 Apr 2015 02:27:14 +0000 (22:27 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/scsi/sg.c

index b5a4db8832236053fd0b516bf8b42eb1493f002b..9d7b7db75e4b96b6fbb33bf24b91c205add07d79 100644 (file)
@@ -1744,21 +1744,15 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
                        md->from_user = 0;
        }
 
-       if (unlikely(iov_count > MAX_UIOVEC))
-               return -EINVAL;
-
        if (iov_count) {
-               int size = sizeof(struct iovec) * iov_count;
-               struct iovec *iov;
+               struct iovec *iov = NULL;
                struct iov_iter i;
 
-               iov = memdup_user(hp->dxferp, size);
-               if (IS_ERR(iov))
-                       return PTR_ERR(iov);
+               res = import_iovec(rw, hp->dxferp, iov_count, 0, &iov, &i);
+               if (res < 0)
+                       return res;
 
-               iov_iter_init(&i, rw, iov, iov_count,
-                             min_t(size_t, hp->dxfer_len,
-                                   iov_length(iov, iov_count)));
+               iov_iter_truncate(&i, hp->dxfer_len);
 
                res = blk_rq_map_user_iov(q, rq, md, &i, GFP_ATOMIC);
                kfree(iov);