2 * Copyright (C) 2014 Sergey Senozhatsky.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #include <linux/lz4.h>
13 #include <linux/vmalloc.h>
16 #include "zcomp_lz4.h"
18 static void *zcomp_lz4_create(gfp_t flags)
22 ret = kzalloc(LZ4_MEM_COMPRESS, flags);
24 ret = __vmalloc(LZ4_MEM_COMPRESS,
25 flags | __GFP_ZERO | __GFP_HIGHMEM,
30 static void zcomp_lz4_destroy(void *private)
35 static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst,
36 size_t *dst_len, void *private)
38 /* return : Success if return 0 */
39 return lz4_compress(src, PAGE_SIZE, dst, dst_len, private);
42 static int zcomp_lz4_decompress(const unsigned char *src, size_t src_len,
45 size_t dst_len = PAGE_SIZE;
46 /* return : Success if return 0 */
47 return lz4_decompress_unknownoutputsize(src, src_len, dst, &dst_len);
50 struct zcomp_backend zcomp_lz4 = {
51 .compress = zcomp_lz4_compress,
52 .decompress = zcomp_lz4_decompress,
53 .create = zcomp_lz4_create,
54 .destroy = zcomp_lz4_destroy,