crypto: scompress - use sgl_alloc() and sgl_free()
Use the sgl_alloc() and sgl_free() functions instead of open coding these functions. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
e80a0af475
commit
8cd579d279
2 changed files with 3 additions and 49 deletions
|
@ -106,6 +106,7 @@ config CRYPTO_KPP
|
||||||
config CRYPTO_ACOMP2
|
config CRYPTO_ACOMP2
|
||||||
tristate
|
tristate
|
||||||
select CRYPTO_ALGAPI2
|
select CRYPTO_ALGAPI2
|
||||||
|
select SGL_ALLOC
|
||||||
|
|
||||||
config CRYPTO_ACOMP
|
config CRYPTO_ACOMP
|
||||||
tristate
|
tristate
|
||||||
|
|
|
@ -140,53 +140,6 @@ static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
|
||||||
return ret;
|
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)
|
static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
|
||||||
{
|
{
|
||||||
struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
|
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);
|
scratch_dst, &req->dlen, *ctx);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
if (!req->dst) {
|
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)
|
if (!req->dst)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +227,7 @@ int crypto_init_scomp_ops_async(struct crypto_tfm *tfm)
|
||||||
|
|
||||||
crt->compress = scomp_acomp_compress;
|
crt->compress = scomp_acomp_compress;
|
||||||
crt->decompress = scomp_acomp_decompress;
|
crt->decompress = scomp_acomp_decompress;
|
||||||
crt->dst_free = crypto_scomp_sg_free;
|
crt->dst_free = sgl_free;
|
||||||
crt->reqsize = sizeof(void *);
|
crt->reqsize = sizeof(void *);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue