xref: /linux/drivers/block/zram/backend_lzo.c (revision 52c7b4e2ba508a924c991e681db534e66a851adf)
12152247cSSergey Senozhatsky // SPDX-License-Identifier: GPL-2.0-or-later
22152247cSSergey Senozhatsky 
32152247cSSergey Senozhatsky #include <linux/kernel.h>
42152247cSSergey Senozhatsky #include <linux/slab.h>
52152247cSSergey Senozhatsky #include <linux/lzo.h>
62152247cSSergey Senozhatsky 
72152247cSSergey Senozhatsky #include "backend_lzo.h"
82152247cSSergey Senozhatsky 
9f2bac7adSSergey Senozhatsky static void *lzo_create(struct zcomp_params *params)
102152247cSSergey Senozhatsky {
112152247cSSergey Senozhatsky 	return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
122152247cSSergey Senozhatsky }
132152247cSSergey Senozhatsky 
142152247cSSergey Senozhatsky static void lzo_destroy(void *ctx)
152152247cSSergey Senozhatsky {
162152247cSSergey Senozhatsky 	kfree(ctx);
172152247cSSergey Senozhatsky }
182152247cSSergey Senozhatsky 
19*52c7b4e2SSergey Senozhatsky static int lzo_compress(void *ctx, struct zcomp_req *req)
202152247cSSergey Senozhatsky {
212152247cSSergey Senozhatsky 	int ret;
222152247cSSergey Senozhatsky 
23*52c7b4e2SSergey Senozhatsky 	ret = lzo1x_1_compress(req->src, req->src_len, req->dst,
24*52c7b4e2SSergey Senozhatsky 			       &req->dst_len, ctx);
252152247cSSergey Senozhatsky 	return ret == LZO_E_OK ? 0 : ret;
262152247cSSergey Senozhatsky }
272152247cSSergey Senozhatsky 
28*52c7b4e2SSergey Senozhatsky static int lzo_decompress(void *ctx, struct zcomp_req *req)
292152247cSSergey Senozhatsky {
302152247cSSergey Senozhatsky 	int ret;
312152247cSSergey Senozhatsky 
32*52c7b4e2SSergey Senozhatsky 	ret = lzo1x_decompress_safe(req->src, req->src_len,
33*52c7b4e2SSergey Senozhatsky 				    req->dst, &req->dst_len);
342152247cSSergey Senozhatsky 	return ret == LZO_E_OK ? 0 : ret;
352152247cSSergey Senozhatsky }
362152247cSSergey Senozhatsky 
372152247cSSergey Senozhatsky const struct zcomp_ops backend_lzo = {
382152247cSSergey Senozhatsky 	.compress	= lzo_compress,
392152247cSSergey Senozhatsky 	.decompress	= lzo_decompress,
402152247cSSergey Senozhatsky 	.create_ctx	= lzo_create,
412152247cSSergey Senozhatsky 	.destroy_ctx	= lzo_destroy,
422152247cSSergey Senozhatsky 	.name		= "lzo",
432152247cSSergey Senozhatsky };
44