xref: /linux/drivers/block/zram/backend_842.c (revision 06a130e42a5bfc84795464bff023bff4c16f58c5)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #include <linux/kernel.h>
4 #include <linux/slab.h>
5 #include <linux/sw842.h>
6 #include <linux/vmalloc.h>
7 
8 #include "backend_842.h"
9 
10 static void release_params_842(struct zcomp_params *params)
11 {
12 }
13 
14 static int setup_params_842(struct zcomp_params *params)
15 {
16 	return 0;
17 }
18 
19 static void destroy_842(struct zcomp_ctx *ctx)
20 {
21 	kfree(ctx->context);
22 }
23 
24 static int create_842(struct zcomp_params *params, struct zcomp_ctx *ctx)
25 {
26 	ctx->context = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
27 	if (!ctx->context)
28 		return -ENOMEM;
29 	return 0;
30 }
31 
32 static int compress_842(struct zcomp_params *params, struct zcomp_ctx *ctx,
33 			struct zcomp_req *req)
34 {
35 	unsigned int dlen = req->dst_len;
36 	int ret;
37 
38 	ret = sw842_compress(req->src, req->src_len, req->dst, &dlen,
39 			     ctx->context);
40 	if (ret == 0)
41 		req->dst_len = dlen;
42 	return ret;
43 }
44 
45 static int decompress_842(struct zcomp_params *params, struct zcomp_ctx *ctx,
46 			  struct zcomp_req *req)
47 {
48 	unsigned int dlen = req->dst_len;
49 
50 	return sw842_decompress(req->src, req->src_len, req->dst, &dlen);
51 }
52 
53 const struct zcomp_ops backend_842 = {
54 	.compress	= compress_842,
55 	.decompress	= decompress_842,
56 	.create_ctx	= create_842,
57 	.destroy_ctx	= destroy_842,
58 	.setup_params	= setup_params_842,
59 	.release_params	= release_params_842,
60 	.name		= "842",
61 };
62