aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/af_alg.c18
-rw-r--r--include/crypto/if_alg.h4
2 files changed, 16 insertions, 6 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 7f8b7edcadca..26089d182cb7 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -358,8 +358,8 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len)
358 npages = (off + n + PAGE_SIZE - 1) >> PAGE_SHIFT; 358 npages = (off + n + PAGE_SIZE - 1) >> PAGE_SHIFT;
359 if (WARN_ON(npages == 0)) 359 if (WARN_ON(npages == 0))
360 return -EINVAL; 360 return -EINVAL;
361 361 /* Add one extra for linking */
362 sg_init_table(sgl->sg, npages); 362 sg_init_table(sgl->sg, npages + 1);
363 363
364 for (i = 0, len = n; i < npages; i++) { 364 for (i = 0, len = n; i < npages; i++) {
365 int plen = min_t(int, len, PAGE_SIZE - off); 365 int plen = min_t(int, len, PAGE_SIZE - off);
@@ -369,18 +369,26 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len)
369 off = 0; 369 off = 0;
370 len -= plen; 370 len -= plen;
371 } 371 }
372 sg_mark_end(sgl->sg + npages - 1);
373 sgl->npages = npages;
374
372 return n; 375 return n;
373} 376}
374EXPORT_SYMBOL_GPL(af_alg_make_sg); 377EXPORT_SYMBOL_GPL(af_alg_make_sg);
375 378
379void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new)
380{
381 sg_unmark_end(sgl_prev->sg + sgl_prev->npages - 1);
382 sg_chain(sgl_prev->sg, sgl_prev->npages + 1, sgl_new->sg);
383}
384EXPORT_SYMBOL(af_alg_link_sg);
385
376void af_alg_free_sg(struct af_alg_sgl *sgl) 386void af_alg_free_sg(struct af_alg_sgl *sgl)
377{ 387{
378 int i; 388 int i;
379 389
380 i = 0; 390 for (i = 0; i < sgl->npages; i++)
381 do {
382 put_page(sgl->pages[i]); 391 put_page(sgl->pages[i]);
383 } while (!sg_is_last(sgl->sg + (i++)));
384} 392}
385EXPORT_SYMBOL_GPL(af_alg_free_sg); 393EXPORT_SYMBOL_GPL(af_alg_free_sg);
386 394
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
index 178525e5f430..018afb264ac2 100644
--- a/include/crypto/if_alg.h
+++ b/include/crypto/if_alg.h
@@ -58,8 +58,9 @@ struct af_alg_type {
58}; 58};
59 59
60struct af_alg_sgl { 60struct af_alg_sgl {
61 struct scatterlist sg[ALG_MAX_PAGES]; 61 struct scatterlist sg[ALG_MAX_PAGES + 1];
62 struct page *pages[ALG_MAX_PAGES]; 62 struct page *pages[ALG_MAX_PAGES];
63 unsigned int npages;
63}; 64};
64 65
65int af_alg_register_type(const struct af_alg_type *type); 66int af_alg_register_type(const struct af_alg_type *type);
@@ -70,6 +71,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock);
70 71
71int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); 72int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len);
72void af_alg_free_sg(struct af_alg_sgl *sgl); 73void af_alg_free_sg(struct af_alg_sgl *sgl);
74void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new);
73 75
74int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); 76int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
75 77