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_lzorle.h" 8 9 static void *lzorle_create(void) 10 { 11 return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 12 } 13 14 static void lzorle_destroy(void *ctx) 15 { 16 kfree(ctx); 17 } 18 19 static int lzorle_compress(void *ctx, const unsigned char *src, size_t src_len, 20 unsigned char *dst, size_t *dst_len) 21 { 22 int ret; 23 24 ret = lzorle1x_1_compress(src, src_len, dst, dst_len, ctx); 25 return ret == LZO_E_OK ? 0 : ret; 26 } 27 28 static int lzorle_decompress(void *ctx, const unsigned char *src, 29 size_t src_len, unsigned char *dst, 30 size_t dst_len) 31 { 32 int ret; 33 34 ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len); 35 return ret == LZO_E_OK ? 0 : ret; 36 } 37 38 const struct zcomp_ops backend_lzorle = { 39 .compress = lzorle_compress, 40 .decompress = lzorle_decompress, 41 .create_ctx = lzorle_create, 42 .destroy_ctx = lzorle_destroy, 43 .name = "lzo-rle", 44 }; 45