Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / block / zram / backend_lzo.c
blob4c906beaae6b33fcde1af419596317f7d4196c09
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_lzo.h"
9 static void lzo_release_params(struct zcomp_params *params)
13 static int lzo_setup_params(struct zcomp_params *params)
15 return 0;
18 static int lzo_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 lzo_destroy(struct zcomp_ctx *ctx)
28 kfree(ctx->context);
31 static int lzo_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
32 struct zcomp_req *req)
34 int ret;
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;
41 static int lzo_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_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",