1 // SPDX-License-Identifier: GPL-2.0-or-later 2 3 #include <linux/kernel.h> 4 #include <linux/slab.h> 5 #include <linux/lzo.h> 6 7 #include "backend_lzo.h" 8 9 static void lzo_release_params(struct zcomp_params *params) 10 { 11 } 12 13 static int lzo_setup_params(struct zcomp_params *params) 14 { 15 return 0; 16 } 17 18 static int lzo_create(struct zcomp_params *params, struct zcomp_ctx *ctx) 19 { 20 ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 21 if (!ctx->context) 22 return -ENOMEM; 23 return 0; 24 } 25 26 static void lzo_destroy(struct zcomp_ctx *ctx) 27 { 28 kfree(ctx->context); 29 } 30 31 static int lzo_compress(struct zcomp_params *params, struct zcomp_ctx *ctx, 32 struct zcomp_req *req) 33 { 34 int ret; 35 36 ret = lzo1x_1_compress(req->src, req->src_len, req->dst, 37 &req->dst_len, ctx->context); 38 return ret == LZO_E_OK ? 0 : ret; 39 } 40 41 static int lzo_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx, 42 struct zcomp_req *req) 43 { 44 int ret; 45 46 ret = lzo1x_decompress_safe(req->src, req->src_len, 47 req->dst, &req->dst_len); 48 return ret == LZO_E_OK ? 0 : ret; 49 } 50 51 const struct zcomp_ops backend_lzo = { 52 .compress = lzo_compress, 53 .decompress = lzo_decompress, 54 .create_ctx = lzo_create, 55 .destroy_ctx = lzo_destroy, 56 .setup_params = lzo_setup_params, 57 .release_params = lzo_release_params, 58 .name = "lzo", 59 }; 60