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