1 // SPDX-License-Identifier: GPL-2.0-or-later 2 3 #define pr_fmt(fmt) "lzo-rle: " fmt 4 5 #include <linux/kernel.h> 6 #include <linux/slab.h> 7 #include <linux/lzo.h> 8 9 #include "backend_lzorle.h" 10 11 static void lzorle_release_params(struct zcomp_params *params) 12 { 13 } 14 15 static int lzorle_setup_params(struct zcomp_params *params) 16 { 17 if (params->dict_sz) { 18 pr_err("dictionary is not supported\n"); 19 return -EOPNOTSUPP; 20 } 21 if (params->level != ZCOMP_PARAM_NOT_SET) { 22 pr_err("compression level is not supported\n"); 23 return -EOPNOTSUPP; 24 } 25 return 0; 26 } 27 28 static int lzorle_create(struct zcomp_params *params, struct zcomp_ctx *ctx) 29 { 30 ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 31 if (!ctx->context) 32 return -ENOMEM; 33 return 0; 34 } 35 36 static void lzorle_destroy(struct zcomp_ctx *ctx) 37 { 38 kfree(ctx->context); 39 } 40 41 static int lzorle_compress(struct zcomp_params *params, struct zcomp_ctx *ctx, 42 struct zcomp_req *req) 43 { 44 int ret; 45 46 ret = lzorle1x_1_compress(req->src, req->src_len, req->dst, 47 &req->dst_len, ctx->context); 48 return ret == LZO_E_OK ? 0 : ret; 49 } 50 51 static int lzorle_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx, 52 struct zcomp_req *req) 53 { 54 int ret; 55 56 ret = lzo1x_decompress_safe(req->src, req->src_len, 57 req->dst, &req->dst_len); 58 return ret == LZO_E_OK ? 0 : ret; 59 } 60 61 const struct zcomp_ops backend_lzorle = { 62 .compress = lzorle_compress, 63 .decompress = lzorle_decompress, 64 .create_ctx = lzorle_create, 65 .destroy_ctx = lzorle_destroy, 66 .setup_params = lzorle_setup_params, 67 .release_params = lzorle_release_params, 68 .name = "lzo-rle", 69 }; 70