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, linux-crypto@vger.kernel.org,
Bart Van Assche <bart.vanassche@wdc.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH v2 2/8] crypto: scompress - use sgl_alloc() and sgl_free()
Date: Mon, 16 Oct 2017 15:49:34 -0700 [thread overview]
Message-ID: <20171016224940.1332-3-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20171016224940.1332-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 | 51 ++-------------------------------------------------
2 files changed, 3 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..968bbcf65c94 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -140,53 +140,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 +173,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, GFP_ATOMIC, NULL);
if (!req->dst)
goto out;
}
@@ -274,7 +227,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-16 22:49 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-16 22:49 [PATCH v2 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
2017-10-16 22:49 ` [PATCH v2 1/8] lib/scatterlist: " Bart Van Assche
2017-10-17 6:06 ` Hannes Reinecke
2017-10-17 9:20 ` Johannes Thumshirn
2017-10-16 22:49 ` Bart Van Assche [this message]
2017-10-17 6:07 ` [PATCH v2 2/8] crypto: scompress - use " Hannes Reinecke
2017-11-01 14:50 ` Bart Van Assche
2017-11-01 15:17 ` Ard Biesheuvel
2017-11-01 15:45 ` Bart Van Assche
2017-11-01 15:51 ` Ard Biesheuvel
2017-10-16 22:49 ` [PATCH v2 3/8] nvmet/fc: Use " Bart Van Assche
2017-10-17 6:07 ` Hannes Reinecke
2017-10-16 22:49 ` [PATCH v2 4/8] nvmet/rdma: " Bart Van Assche
2017-10-17 6:08 ` Hannes Reinecke
2017-10-16 22:49 ` [PATCH v2 5/8] target: Use sgl_alloc_order() " Bart Van Assche
2017-10-17 6:14 ` Hannes Reinecke
2017-10-17 14:31 ` Bart Van Assche
2017-10-16 22:49 ` [PATCH v2 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-17 6:19 ` Hannes Reinecke
2017-10-18 20:57 ` Brian King
2017-10-30 20:37 ` Bart Van Assche
2017-10-30 21:01 ` Brian King
2017-11-01 11:13 ` Hannes Reinecke
2017-10-16 22:49 ` [PATCH v2 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
2017-10-17 6:21 ` Hannes Reinecke
2017-10-17 14:28 ` Bart Van Assche
2017-10-16 22:49 ` [PATCH v2 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-17 6:22 ` Hannes Reinecke
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=20171016224940.1332-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-crypto@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;
as well as URLs for NNTP newsgroup(s).