Skip to content

Commit 7ab24bf

Browse files
committed
net+crypto: Use vmalloc for zlib inflate buffers.
They are 64K and result in order-4 allocations, even with SLUB. Therefore, just like we always have for the deflate buffers, use vmalloc. Reported-by: Martin Jackson <[email protected]> Acked-by: Herbert Xu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ed6e4ef commit 7ab24bf

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

crypto/deflate.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <linux/interrupt.h>
3333
#include <linux/mm.h>
3434
#include <linux/net.h>
35-
#include <linux/slab.h>
3635

3736
#define DEFLATE_DEF_LEVEL Z_DEFAULT_COMPRESSION
3837
#define DEFLATE_DEF_WINBITS 11
@@ -73,7 +72,7 @@ static int deflate_decomp_init(struct deflate_ctx *ctx)
7372
int ret = 0;
7473
struct z_stream_s *stream = &ctx->decomp_stream;
7574

76-
stream->workspace = kzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
75+
stream->workspace = vzalloc(zlib_inflate_workspacesize());
7776
if (!stream->workspace) {
7877
ret = -ENOMEM;
7978
goto out;
@@ -86,7 +85,7 @@ static int deflate_decomp_init(struct deflate_ctx *ctx)
8685
out:
8786
return ret;
8887
out_free:
89-
kfree(stream->workspace);
88+
vfree(stream->workspace);
9089
goto out;
9190
}
9291

@@ -99,7 +98,7 @@ static void deflate_comp_exit(struct deflate_ctx *ctx)
9998
static void deflate_decomp_exit(struct deflate_ctx *ctx)
10099
{
101100
zlib_inflateEnd(&ctx->decomp_stream);
102-
kfree(ctx->decomp_stream.workspace);
101+
vfree(ctx->decomp_stream.workspace);
103102
}
104103

105104
static int deflate_init(struct crypto_tfm *tfm)

crypto/zlib.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <linux/interrupt.h>
3030
#include <linux/mm.h>
3131
#include <linux/net.h>
32-
#include <linux/slab.h>
3332

3433
#include <crypto/internal/compress.h>
3534

@@ -60,7 +59,7 @@ static void zlib_decomp_exit(struct zlib_ctx *ctx)
6059

6160
if (stream->workspace) {
6261
zlib_inflateEnd(stream);
63-
kfree(stream->workspace);
62+
vfree(stream->workspace);
6463
stream->workspace = NULL;
6564
}
6665
}
@@ -228,13 +227,13 @@ static int zlib_decompress_setup(struct crypto_pcomp *tfm, void *params,
228227
? nla_get_u32(tb[ZLIB_DECOMP_WINDOWBITS])
229228
: DEF_WBITS;
230229

231-
stream->workspace = kzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
230+
stream->workspace = vzalloc(zlib_inflate_workspacesize());
232231
if (!stream->workspace)
233232
return -ENOMEM;
234233

235234
ret = zlib_inflateInit2(stream, ctx->decomp_windowBits);
236235
if (ret != Z_OK) {
237-
kfree(stream->workspace);
236+
vfree(stream->workspace);
238237
stream->workspace = NULL;
239238
return -EINVAL;
240239
}

drivers/net/bnx2x/bnx2x_main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <linux/zlib.h>
5050
#include <linux/io.h>
5151
#include <linux/stringify.h>
52+
#include <linux/vmalloc.h>
5253

5354
#define BNX2X_MAIN
5455
#include "bnx2x.h"
@@ -4537,8 +4538,7 @@ static int bnx2x_gunzip_init(struct bnx2x *bp)
45374538
if (bp->strm == NULL)
45384539
goto gunzip_nomem2;
45394540

4540-
bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
4541-
GFP_KERNEL);
4541+
bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
45424542
if (bp->strm->workspace == NULL)
45434543
goto gunzip_nomem3;
45444544

@@ -4562,7 +4562,7 @@ static int bnx2x_gunzip_init(struct bnx2x *bp)
45624562
static void bnx2x_gunzip_end(struct bnx2x *bp)
45634563
{
45644564
if (bp->strm) {
4565-
kfree(bp->strm->workspace);
4565+
vfree(bp->strm->workspace);
45664566
kfree(bp->strm);
45674567
bp->strm = NULL;
45684568
}

drivers/net/ppp_deflate.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void z_decomp_free(void *arg)
305305

306306
if (state) {
307307
zlib_inflateEnd(&state->strm);
308-
kfree(state->strm.workspace);
308+
vfree(state->strm.workspace);
309309
kfree(state);
310310
}
311311
}
@@ -345,8 +345,7 @@ static void *z_decomp_alloc(unsigned char *options, int opt_len)
345345

346346
state->w_size = w_size;
347347
state->strm.next_out = NULL;
348-
state->strm.workspace = kmalloc(zlib_inflate_workspacesize(),
349-
GFP_KERNEL|__GFP_REPEAT);
348+
state->strm.workspace = vmalloc(zlib_inflate_workspacesize());
350349
if (state->strm.workspace == NULL)
351350
goto out_free;
352351

0 commit comments

Comments
 (0)