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 9*6a81bdfeSSergey Senozhatsky static int lzo_create(struct zcomp_params *params, struct zcomp_ctx *ctx) 102152247cSSergey Senozhatsky { 11*6a81bdfeSSergey Senozhatsky ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 12*6a81bdfeSSergey Senozhatsky if (!ctx->context) 13*6a81bdfeSSergey Senozhatsky return -ENOMEM; 14*6a81bdfeSSergey Senozhatsky return 0; 152152247cSSergey Senozhatsky } 162152247cSSergey Senozhatsky 17*6a81bdfeSSergey Senozhatsky static void lzo_destroy(struct zcomp_ctx *ctx) 182152247cSSergey Senozhatsky { 19*6a81bdfeSSergey Senozhatsky kfree(ctx->context); 202152247cSSergey Senozhatsky } 212152247cSSergey Senozhatsky 22*6a81bdfeSSergey Senozhatsky static int lzo_compress(struct zcomp_ctx *ctx, struct zcomp_req *req) 232152247cSSergey Senozhatsky { 242152247cSSergey Senozhatsky int ret; 252152247cSSergey Senozhatsky 2652c7b4e2SSergey Senozhatsky ret = lzo1x_1_compress(req->src, req->src_len, req->dst, 27*6a81bdfeSSergey Senozhatsky &req->dst_len, ctx->context); 282152247cSSergey Senozhatsky return ret == LZO_E_OK ? 0 : ret; 292152247cSSergey Senozhatsky } 302152247cSSergey Senozhatsky 31*6a81bdfeSSergey Senozhatsky static int lzo_decompress(struct zcomp_ctx *ctx, struct zcomp_req *req) 322152247cSSergey Senozhatsky { 332152247cSSergey Senozhatsky int ret; 342152247cSSergey Senozhatsky 3552c7b4e2SSergey Senozhatsky ret = lzo1x_decompress_safe(req->src, req->src_len, 3652c7b4e2SSergey Senozhatsky req->dst, &req->dst_len); 372152247cSSergey Senozhatsky return ret == LZO_E_OK ? 0 : ret; 382152247cSSergey Senozhatsky } 392152247cSSergey Senozhatsky 402152247cSSergey Senozhatsky const struct zcomp_ops backend_lzo = { 412152247cSSergey Senozhatsky .compress = lzo_compress, 422152247cSSergey Senozhatsky .decompress = lzo_decompress, 432152247cSSergey Senozhatsky .create_ctx = lzo_create, 442152247cSSergey Senozhatsky .destroy_ctx = lzo_destroy, 452152247cSSergey Senozhatsky .name = "lzo", 462152247cSSergey Senozhatsky }; 47