xref: /linux/drivers/block/zram/backend_lzorle.c (revision 617a814f14b8914271f7a70366d72c6196d17663)
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_release_params(struct zcomp_params *params)
10 {
11 }
12 
13 static int lzorle_setup_params(struct zcomp_params *params)
14 {
15 	return 0;
16 }
17 
18 static int lzorle_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
19 {
20 	ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
21 	if (!ctx->context)
22 		return -ENOMEM;
23 	return 0;
24 }
25 
26 static void lzorle_destroy(struct zcomp_ctx *ctx)
27 {
28 	kfree(ctx->context);
29 }
30 
31 static int lzorle_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
32 			   struct zcomp_req *req)
33 {
34 	int ret;
35 
36 	ret = lzorle1x_1_compress(req->src, req->src_len, req->dst,
37 				  &req->dst_len, ctx->context);
38 	return ret == LZO_E_OK ? 0 : ret;
39 }
40 
41 static int lzorle_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
42 			     struct zcomp_req *req)
43 {
44 	int ret;
45 
46 	ret = lzo1x_decompress_safe(req->src, req->src_len,
47 				    req->dst, &req->dst_len);
48 	return ret == LZO_E_OK ? 0 : ret;
49 }
50 
51 const struct zcomp_ops backend_lzorle = {
52 	.compress	= lzorle_compress,
53 	.decompress	= lzorle_decompress,
54 	.create_ctx	= lzorle_create,
55 	.destroy_ctx	= lzorle_destroy,
56 	.setup_params	= lzorle_setup_params,
57 	.release_params	= lzorle_release_params,
58 	.name		= "lzo-rle",
59 };
60