Linux 6.13-rc4
[linux.git] / drivers / block / zram / backend_lzorle.c
blob10640c96cbfcaae862d4f3e2f6797864d475581f
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/kernel.h>
4 #include <linux/slab.h>
5 #include <linux/lzo.h>
7 #include "backend_lzorle.h"
9 static void lzorle_release_params(struct zcomp_params *params)
13 static int lzorle_setup_params(struct zcomp_params *params)
15 return 0;
18 static int lzorle_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
20 ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
21 if (!ctx->context)
22 return -ENOMEM;
23 return 0;
26 static void lzorle_destroy(struct zcomp_ctx *ctx)
28 kfree(ctx->context);
31 static int lzorle_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
32 struct zcomp_req *req)
34 int ret;
36 ret = lzorle1x_1_compress(req->src, req->src_len, req->dst,
37 &req->dst_len, ctx->context);
38 return ret == LZO_E_OK ? 0 : ret;
41 static int lzorle_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
42 struct zcomp_req *req)
44 int ret;
46 ret = lzo1x_decompress_safe(req->src, req->src_len,
47 req->dst, &req->dst_len);
48 return ret == LZO_E_OK ? 0 : ret;
51 const struct zcomp_ops backend_lzorle = {
52 .compress = lzorle_compress,
53 .decompress = lzorle_decompress,
54 .create_ctx = lzorle_create,
55 .destroy_ctx = lzorle_destroy,
56 .setup_params = lzorle_setup_params,
57 .release_params = lzorle_release_params,
58 .name = "lzo-rle",