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_lzorle.h" 82152247cSSergey Senozhatsky 9*b8f03cb7SSergey Senozhatsky static void lzorle_release_params(struct zcomp_params *params) 10*b8f03cb7SSergey Senozhatsky { 11*b8f03cb7SSergey Senozhatsky } 12*b8f03cb7SSergey Senozhatsky 13*b8f03cb7SSergey Senozhatsky static int lzorle_setup_params(struct zcomp_params *params) 14*b8f03cb7SSergey Senozhatsky { 15*b8f03cb7SSergey Senozhatsky return 0; 16*b8f03cb7SSergey Senozhatsky } 17*b8f03cb7SSergey Senozhatsky 186a81bdfeSSergey Senozhatsky static int lzorle_create(struct zcomp_params *params, struct zcomp_ctx *ctx) 192152247cSSergey Senozhatsky { 206a81bdfeSSergey Senozhatsky ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 216a81bdfeSSergey Senozhatsky if (!ctx->context) 226a81bdfeSSergey Senozhatsky return -ENOMEM; 236a81bdfeSSergey Senozhatsky return 0; 242152247cSSergey Senozhatsky } 252152247cSSergey Senozhatsky 266a81bdfeSSergey Senozhatsky static void lzorle_destroy(struct zcomp_ctx *ctx) 272152247cSSergey Senozhatsky { 286a81bdfeSSergey Senozhatsky kfree(ctx->context); 292152247cSSergey Senozhatsky } 302152247cSSergey Senozhatsky 31*b8f03cb7SSergey Senozhatsky static int lzorle_compress(struct zcomp_params *params, struct zcomp_ctx *ctx, 32*b8f03cb7SSergey Senozhatsky struct zcomp_req *req) 332152247cSSergey Senozhatsky { 342152247cSSergey Senozhatsky int ret; 352152247cSSergey Senozhatsky 3652c7b4e2SSergey Senozhatsky ret = lzorle1x_1_compress(req->src, req->src_len, req->dst, 376a81bdfeSSergey Senozhatsky &req->dst_len, ctx->context); 382152247cSSergey Senozhatsky return ret == LZO_E_OK ? 0 : ret; 392152247cSSergey Senozhatsky } 402152247cSSergey Senozhatsky 41*b8f03cb7SSergey Senozhatsky static int lzorle_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx, 42*b8f03cb7SSergey Senozhatsky struct zcomp_req *req) 432152247cSSergey Senozhatsky { 442152247cSSergey Senozhatsky int ret; 452152247cSSergey Senozhatsky 4652c7b4e2SSergey Senozhatsky ret = lzo1x_decompress_safe(req->src, req->src_len, 4752c7b4e2SSergey Senozhatsky req->dst, &req->dst_len); 482152247cSSergey Senozhatsky return ret == LZO_E_OK ? 0 : ret; 492152247cSSergey Senozhatsky } 502152247cSSergey Senozhatsky 512152247cSSergey Senozhatsky const struct zcomp_ops backend_lzorle = { 522152247cSSergey Senozhatsky .compress = lzorle_compress, 532152247cSSergey Senozhatsky .decompress = lzorle_decompress, 542152247cSSergey Senozhatsky .create_ctx = lzorle_create, 552152247cSSergey Senozhatsky .destroy_ctx = lzorle_destroy, 56*b8f03cb7SSergey Senozhatsky .setup_params = lzorle_setup_params, 57*b8f03cb7SSergey Senozhatsky .release_params = lzorle_release_params, 582152247cSSergey Senozhatsky .name = "lzo-rle", 592152247cSSergey Senozhatsky }; 60