Merge branch 'cleanups'
[linux-drm-fsl-dcu.git] / crypto / algif_hash.c
index 01f56eb7816ee4320a9acd9632c3e4b5bc3233ee..01da360bdb5510b78eac0ee43630795c4a011d76 100644 (file)
@@ -41,8 +41,6 @@ static int hash_sendmsg(struct kiocb *unused, struct socket *sock,
        struct sock *sk = sock->sk;
        struct alg_sock *ask = alg_sk(sk);
        struct hash_ctx *ctx = ask->private;
-       unsigned long iovlen;
-       const struct iovec *iov;
        long copied = 0;
        int err;
 
@@ -58,37 +56,28 @@ static int hash_sendmsg(struct kiocb *unused, struct socket *sock,
 
        ctx->more = 0;
 
-       for (iov = msg->msg_iter.iov, iovlen = msg->msg_iter.nr_segs; iovlen > 0;
-            iovlen--, iov++) {
-               unsigned long seglen = iov->iov_len;
-               char __user *from = iov->iov_base;
+       while (iov_iter_count(&msg->msg_iter)) {
+               int len = iov_iter_count(&msg->msg_iter);
 
-               while (seglen) {
-                       int len = min_t(unsigned long, seglen, limit);
-                       int newlen;
+               if (len > limit)
+                       len = limit;
 
-                       newlen = af_alg_make_sg(&ctx->sgl, from, len, 0);
-                       if (newlen < 0) {
-                               err = copied ? 0 : newlen;
-                               goto unlock;
-                       }
-
-                       ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL,
-                                               newlen);
-
-                       err = af_alg_wait_for_completion(
-                               crypto_ahash_update(&ctx->req),
-                               &ctx->completion);
+               len = af_alg_make_sg(&ctx->sgl, &msg->msg_iter, len);
+               if (len < 0) {
+                       err = copied ? 0 : len;
+                       goto unlock;
+               }
 
-                       af_alg_free_sg(&ctx->sgl);
+               ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len);
 
-                       if (err)
-                               goto unlock;
+               err = af_alg_wait_for_completion(crypto_ahash_update(&ctx->req),
+                                                &ctx->completion);
+               af_alg_free_sg(&ctx->sgl);
+               if (err)
+                       goto unlock;
 
-                       seglen -= newlen;
-                       from += newlen;
-                       copied += newlen;
-               }
+               copied += len;
+               iov_iter_advance(&msg->msg_iter, len);
        }
 
        err = 0;