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*f2bac7adSSergey Senozhatsky static void *lzo_create(struct zcomp_params *params) 102152247cSSergey Senozhatsky { 112152247cSSergey Senozhatsky return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 122152247cSSergey Senozhatsky } 132152247cSSergey Senozhatsky 142152247cSSergey Senozhatsky static void lzo_destroy(void *ctx) 152152247cSSergey Senozhatsky { 162152247cSSergey Senozhatsky kfree(ctx); 172152247cSSergey Senozhatsky } 182152247cSSergey Senozhatsky 192152247cSSergey Senozhatsky static int lzo_compress(void *ctx, const unsigned char *src, size_t src_len, 202152247cSSergey Senozhatsky unsigned char *dst, size_t *dst_len) 212152247cSSergey Senozhatsky { 222152247cSSergey Senozhatsky int ret; 232152247cSSergey Senozhatsky 242152247cSSergey Senozhatsky ret = lzo1x_1_compress(src, src_len, dst, dst_len, ctx); 252152247cSSergey Senozhatsky return ret == LZO_E_OK ? 0 : ret; 262152247cSSergey Senozhatsky } 272152247cSSergey Senozhatsky 282152247cSSergey Senozhatsky static int lzo_decompress(void *ctx, const unsigned char *src, size_t src_len, 292152247cSSergey Senozhatsky unsigned char *dst, size_t dst_len) 302152247cSSergey Senozhatsky { 312152247cSSergey Senozhatsky int ret; 322152247cSSergey Senozhatsky 332152247cSSergey Senozhatsky ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len); 342152247cSSergey Senozhatsky return ret == LZO_E_OK ? 0 : ret; 352152247cSSergey Senozhatsky } 362152247cSSergey Senozhatsky 372152247cSSergey Senozhatsky const struct zcomp_ops backend_lzo = { 382152247cSSergey Senozhatsky .compress = lzo_compress, 392152247cSSergey Senozhatsky .decompress = lzo_decompress, 402152247cSSergey Senozhatsky .create_ctx = lzo_create, 412152247cSSergey Senozhatsky .destroy_ctx = lzo_destroy, 422152247cSSergey Senozhatsky .name = "lzo", 432152247cSSergey Senozhatsky }; 44