Commit 251fdd7f authored by James Morris's avatar James Morris Committed by David S. Miller

[CRYPTO]: Remove lazy allocation from deflate.

Signed-off-by: default avatarJames Morris <jmorris@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@redhat.com>
parent 0760b8e4
......@@ -39,44 +39,16 @@
#define DEFLATE_DEF_MEMLEVEL MAX_MEM_LEVEL
struct deflate_ctx {
int comp_initialized;
int decomp_initialized;
struct z_stream_s comp_stream;
struct z_stream_s decomp_stream;
};
static inline int deflate_gfp(void)
{
return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
}
static int deflate_init(void *ctx)
{
return 0;
}
static void deflate_exit(void *ctx)
{
struct deflate_ctx *dctx = ctx;
if (dctx->comp_initialized)
vfree(dctx->comp_stream.workspace);
if (dctx->decomp_initialized)
kfree(dctx->decomp_stream.workspace);
}
/*
* Lazy initialization to make interface simple without allocating
* un-needed workspaces. Thus can be called in softirq context.
*/
static int deflate_comp_init(struct deflate_ctx *ctx)
{
int ret = 0;
struct z_stream_s *stream = &ctx->comp_stream;
stream->workspace = __vmalloc(zlib_deflate_workspacesize(),
deflate_gfp()|__GFP_HIGHMEM,
PAGE_KERNEL);
stream->workspace = vmalloc(zlib_deflate_workspacesize());
if (!stream->workspace ) {
ret = -ENOMEM;
goto out;
......@@ -89,7 +61,6 @@ static int deflate_comp_init(struct deflate_ctx *ctx)
ret = -EINVAL;
goto out_free;
}
ctx->comp_initialized = 1;
out:
return ret;
out_free:
......@@ -102,8 +73,7 @@ static int deflate_decomp_init(struct deflate_ctx *ctx)
int ret = 0;
struct z_stream_s *stream = &ctx->decomp_stream;
stream->workspace = kmalloc(zlib_inflate_workspacesize(),
deflate_gfp());
stream->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
if (!stream->workspace ) {
ret = -ENOMEM;
goto out;
......@@ -114,7 +84,6 @@ static int deflate_decomp_init(struct deflate_ctx *ctx)
ret = -EINVAL;
goto out_free;
}
ctx->decomp_initialized = 1;
out:
return ret;
out_free:
......@@ -122,6 +91,36 @@ static int deflate_decomp_init(struct deflate_ctx *ctx)
goto out;
}
static void deflate_comp_exit(struct deflate_ctx *ctx)
{
vfree(ctx->comp_stream.workspace);
}
static void deflate_decomp_exit(struct deflate_ctx *ctx)
{
kfree(ctx->decomp_stream.workspace);
}
static int deflate_init(void *ctx)
{
int ret;
ret = deflate_comp_init(ctx);
if (ret)
goto out;
ret = deflate_decomp_init(ctx);
if (ret)
deflate_comp_exit(ctx);
out:
return ret;
}
static void deflate_exit(void *ctx)
{
deflate_comp_exit(ctx);
deflate_decomp_exit(ctx);
}
static int deflate_compress(void *ctx, const u8 *src, unsigned int slen,
u8 *dst, unsigned int *dlen)
{
......@@ -129,12 +128,6 @@ static int deflate_compress(void *ctx, const u8 *src, unsigned int slen,
struct deflate_ctx *dctx = ctx;
struct z_stream_s *stream = &dctx->comp_stream;
if (!dctx->comp_initialized) {
ret = deflate_comp_init(dctx);
if (ret)
goto out;
}
ret = zlib_deflateReset(stream);
if (ret != Z_OK) {
ret = -EINVAL;
......@@ -165,12 +158,6 @@ static int deflate_decompress(void *ctx, const u8 *src, unsigned int slen,
struct deflate_ctx *dctx = ctx;
struct z_stream_s *stream = &dctx->decomp_stream;
if (!dctx->decomp_initialized) {
ret = deflate_decomp_init(dctx);
if (ret)
goto out;
}
ret = zlib_inflateReset(stream);
if (ret != Z_OK) {
ret = -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment