aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/zlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/zlib.c')
-rw-r--r--crypto/zlib.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/crypto/zlib.c b/crypto/zlib.c
index c3015733c990..06b62e5cdcc7 100644
--- a/crypto/zlib.c
+++ b/crypto/zlib.c
@@ -29,7 +29,6 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/mm.h> 30#include <linux/mm.h>
31#include <linux/net.h> 31#include <linux/net.h>
32#include <linux/slab.h>
33 32
34#include <crypto/internal/compress.h> 33#include <crypto/internal/compress.h>
35 34
@@ -60,7 +59,7 @@ static void zlib_decomp_exit(struct zlib_ctx *ctx)
60 59
61 if (stream->workspace) { 60 if (stream->workspace) {
62 zlib_inflateEnd(stream); 61 zlib_inflateEnd(stream);
63 kfree(stream->workspace); 62 vfree(stream->workspace);
64 stream->workspace = NULL; 63 stream->workspace = NULL;
65 } 64 }
66} 65}
@@ -85,6 +84,7 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
85 struct zlib_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm)); 84 struct zlib_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
86 struct z_stream_s *stream = &ctx->comp_stream; 85 struct z_stream_s *stream = &ctx->comp_stream;
87 struct nlattr *tb[ZLIB_COMP_MAX + 1]; 86 struct nlattr *tb[ZLIB_COMP_MAX + 1];
87 int window_bits, mem_level;
88 size_t workspacesize; 88 size_t workspacesize;
89 int ret; 89 int ret;
90 90
@@ -94,12 +94,18 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
94 94
95 zlib_comp_exit(ctx); 95 zlib_comp_exit(ctx);
96 96
97 workspacesize = zlib_deflate_workspacesize(); 97 window_bits = tb[ZLIB_COMP_WINDOWBITS]
98 stream->workspace = vmalloc(workspacesize); 98 ? nla_get_u32(tb[ZLIB_COMP_WINDOWBITS])
99 : MAX_WBITS;
100 mem_level = tb[ZLIB_COMP_MEMLEVEL]
101 ? nla_get_u32(tb[ZLIB_COMP_MEMLEVEL])
102 : DEF_MEM_LEVEL;
103
104 workspacesize = zlib_deflate_workspacesize(window_bits, mem_level);
105 stream->workspace = vzalloc(workspacesize);
99 if (!stream->workspace) 106 if (!stream->workspace)
100 return -ENOMEM; 107 return -ENOMEM;
101 108
102 memset(stream->workspace, 0, workspacesize);
103 ret = zlib_deflateInit2(stream, 109 ret = zlib_deflateInit2(stream,
104 tb[ZLIB_COMP_LEVEL] 110 tb[ZLIB_COMP_LEVEL]
105 ? nla_get_u32(tb[ZLIB_COMP_LEVEL]) 111 ? nla_get_u32(tb[ZLIB_COMP_LEVEL])
@@ -107,12 +113,8 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
107 tb[ZLIB_COMP_METHOD] 113 tb[ZLIB_COMP_METHOD]
108 ? nla_get_u32(tb[ZLIB_COMP_METHOD]) 114 ? nla_get_u32(tb[ZLIB_COMP_METHOD])
109 : Z_DEFLATED, 115 : Z_DEFLATED,
110 tb[ZLIB_COMP_WINDOWBITS] 116 window_bits,
111 ? nla_get_u32(tb[ZLIB_COMP_WINDOWBITS]) 117 mem_level,
112 : MAX_WBITS,
113 tb[ZLIB_COMP_MEMLEVEL]
114 ? nla_get_u32(tb[ZLIB_COMP_MEMLEVEL])
115 : DEF_MEM_LEVEL,
116 tb[ZLIB_COMP_STRATEGY] 118 tb[ZLIB_COMP_STRATEGY]
117 ? nla_get_u32(tb[ZLIB_COMP_STRATEGY]) 119 ? nla_get_u32(tb[ZLIB_COMP_STRATEGY])
118 : Z_DEFAULT_STRATEGY); 120 : Z_DEFAULT_STRATEGY);
@@ -225,13 +227,13 @@ static int zlib_decompress_setup(struct crypto_pcomp *tfm, void *params,
225 ? nla_get_u32(tb[ZLIB_DECOMP_WINDOWBITS]) 227 ? nla_get_u32(tb[ZLIB_DECOMP_WINDOWBITS])
226 : DEF_WBITS; 228 : DEF_WBITS;
227 229
228 stream->workspace = kzalloc(zlib_inflate_workspacesize(), GFP_KERNEL); 230 stream->workspace = vzalloc(zlib_inflate_workspacesize());
229 if (!stream->workspace) 231 if (!stream->workspace)
230 return -ENOMEM; 232 return -ENOMEM;
231 233
232 ret = zlib_inflateInit2(stream, ctx->decomp_windowBits); 234 ret = zlib_inflateInit2(stream, ctx->decomp_windowBits);
233 if (ret != Z_OK) { 235 if (ret != Z_OK) {
234 kfree(stream->workspace); 236 vfree(stream->workspace);
235 stream->workspace = NULL; 237 stream->workspace = NULL;
236 return -EINVAL; 238 return -EINVAL;
237 } 239 }