xref: /linux/drivers/block/zram/backend_lzorle.c (revision 52c7b4e2ba508a924c991e681db534e66a851adf)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #include <linux/kernel.h>
4 #include <linux/slab.h>
5 #include <linux/lzo.h>
6 
7 #include "backend_lzorle.h"
8 
9 static void *lzorle_create(struct zcomp_params *params)
10 {
11 	return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
12 }
13 
14 static void lzorle_destroy(void *ctx)
15 {
16 	kfree(ctx);
17 }
18 
19 static int lzorle_compress(void *ctx, struct zcomp_req *req)
20 {
21 	int ret;
22 
23 	ret = lzorle1x_1_compress(req->src, req->src_len, req->dst,
24 				  &req->dst_len, ctx);
25 	return ret == LZO_E_OK ? 0 : ret;
26 }
27 
28 static int lzorle_decompress(void *ctx, struct zcomp_req *req)
29 {
30 	int ret;
31 
32 	ret = lzo1x_decompress_safe(req->src, req->src_len,
33 				    req->dst, &req->dst_len);
34 	return ret == LZO_E_OK ? 0 : ret;
35 }
36 
37 const struct zcomp_ops backend_lzorle = {
38 	.compress	= lzorle_compress,
39 	.decompress	= lzorle_decompress,
40 	.create_ctx	= lzorle_create,
41 	.destroy_ctx	= lzorle_destroy,
42 	.name		= "lzo-rle",
43 };
44