From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-nvme@lists.infradead.org,
Bart Van Assche <bart.vanassche@wdc.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH 2/8] crypto: scompress - use sgl_alloc() and sgl_free()
Date: Thu, 12 Oct 2017 15:45:44 -0700 [thread overview]
Message-ID: <20171012224550.25440-3-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20171012224550.25440-1-bart.vanassche@wdc.com>
Use the sgl_alloc() and sgl_free() functions instead of open coding
these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/Kconfig | 1 +
crypto/scompress.c | 52 +++-------------------------------------------------
2 files changed, 4 insertions(+), 49 deletions(-)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 0a121f9ddf8e..a0667dd284ff 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -105,6 +105,7 @@ config CRYPTO_KPP
config CRYPTO_ACOMP2
tristate
select CRYPTO_ALGAPI2
+ select SGL_ALLOC
config CRYPTO_ACOMP
tristate
diff --git a/crypto/scompress.c b/crypto/scompress.c
index 2075e2c4e7df..ea4d5a3e01d1 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -24,6 +24,7 @@
#include <linux/cryptouser.h>
#include <net/netlink.h>
#include <linux/scatterlist.h>
+#include <linux/sgl_alloc.h>
#include <crypto/scatterwalk.h>
#include <crypto/internal/acompress.h>
#include <crypto/internal/scompress.h>
@@ -140,53 +141,6 @@ static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
return ret;
}
-static void crypto_scomp_sg_free(struct scatterlist *sgl)
-{
- int i, n;
- struct page *page;
-
- if (!sgl)
- return;
-
- n = sg_nents(sgl);
- for_each_sg(sgl, sgl, n, i) {
- page = sg_page(sgl);
- if (page)
- __free_page(page);
- }
-
- kfree(sgl);
-}
-
-static struct scatterlist *crypto_scomp_sg_alloc(size_t size, gfp_t gfp)
-{
- struct scatterlist *sgl;
- struct page *page;
- int i, n;
-
- n = ((size - 1) >> PAGE_SHIFT) + 1;
-
- sgl = kmalloc_array(n, sizeof(struct scatterlist), gfp);
- if (!sgl)
- return NULL;
-
- sg_init_table(sgl, n);
-
- for (i = 0; i < n; i++) {
- page = alloc_page(gfp);
- if (!page)
- goto err;
- sg_set_page(sgl + i, page, PAGE_SIZE, 0);
- }
-
- return sgl;
-
-err:
- sg_mark_end(sgl + i);
- crypto_scomp_sg_free(sgl);
- return NULL;
-}
-
static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
{
struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
@@ -220,7 +174,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
scratch_dst, &req->dlen, *ctx);
if (!ret) {
if (!req->dst) {
- req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC);
+ req->dst = sgl_alloc(req->dlen, NULL, GFP_ATOMIC);
if (!req->dst)
goto out;
}
@@ -274,7 +228,7 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
crt->compress = scomp_acomp_compress;
crt->decompress = scomp_acomp_decompress;
- crt->dst_free = crypto_scomp_sg_free;
+ crt->dst_free = sgl_free;
crt->reqsize = sizeof(void *);
return 0;
--
2.14.2
next prev parent reply other threads:[~2017-10-12 22:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-12 22:45 [PATCH 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
2017-10-12 22:45 ` [PATCH 1/8] lib: " Bart Van Assche
2017-10-12 22:52 ` Jens Axboe
2017-10-12 23:00 ` Bart Van Assche
2017-10-13 8:44 ` Johannes Thumshirn
2017-10-13 14:20 ` Jens Axboe
2017-10-13 17:43 ` Randy Dunlap
2017-10-13 17:56 ` Bart Van Assche
2017-10-12 22:45 ` Bart Van Assche [this message]
2017-10-12 22:45 ` [PATCH 3/8] nvmet/fc: Use " Bart Van Assche
2017-10-13 8:41 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 4/8] nvmet/rdma: " Bart Van Assche
2017-10-13 8:42 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 5/8] target: Use sgl_alloc_order() " Bart Van Assche
2017-10-12 22:45 ` [PATCH 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-13 8:45 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
2017-10-13 8:45 ` Johannes Thumshirn
2017-10-12 22:45 ` [PATCH 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-13 8:47 ` Johannes Thumshirn
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=20171012224550.25440-3-bart.vanassche@wdc.com \
--to=bart.vanassche@wdc.com \
--cc=ard.biesheuvel@linaro.org \
--cc=axboe@kernel.dk \
--cc=herbert@gondor.apana.org.au \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@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