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/lzo.h>
13 #include <linux/vmalloc.h>
16 #include "zcomp_lzo.h"
18 static void *lzo_create(gfp_t flags
)
22 ret
= kmalloc(LZO1X_MEM_COMPRESS
, flags
);
24 ret
= __vmalloc(LZO1X_MEM_COMPRESS
,
25 flags
| __GFP_HIGHMEM
,
30 static void lzo_destroy(void *private)
35 static int lzo_compress(const unsigned char *src
, unsigned char *dst
,
36 size_t *dst_len
, void *private)
38 int ret
= lzo1x_1_compress(src
, PAGE_SIZE
, dst
, dst_len
, private);
39 return ret
== LZO_E_OK
? 0 : ret
;
42 static int lzo_decompress(const unsigned char *src
, size_t src_len
,
45 size_t dst_len
= PAGE_SIZE
;
46 int ret
= lzo1x_decompress_safe(src
, src_len
, dst
, &dst_len
);
47 return ret
== LZO_E_OK
? 0 : ret
;
50 struct zcomp_backend zcomp_lzo
= {
51 .compress
= lzo_compress
,
52 .decompress
= lzo_decompress
,
54 .destroy
= lzo_destroy
,