1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/sw842.h>
#include <linux/vmalloc.h>
#include "backend_842.h"
struct sw842_ctx {
void *mem;
};
static void destroy_842(void *ctx)
{
struct sw842_ctx *zctx = ctx;
kfree(zctx->mem);
kfree(zctx);
}
static void *create_842(void)
{
struct sw842_ctx *ctx;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return NULL;
ctx->mem = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);
if (!ctx->mem)
goto error;
return ctx;
error:
destroy_842(ctx);
return NULL;
}
static int compress_842(void *ctx, const unsigned char *src, size_t src_len,
unsigned char *dst, size_t *dst_len)
{
struct sw842_ctx *zctx = ctx;
unsigned int dlen = *dst_len;
int ret;
ret = sw842_compress(src, src_len, dst, &dlen, zctx->mem);
if (ret == 0)
*dst_len = dlen;
return ret;
}
static int decompress_842(void *ctx, const unsigned char *src, size_t src_len,
unsigned char *dst, size_t dst_len)
{
unsigned int dlen = dst_len;
return sw842_decompress(src, src_len, dst, &dlen);
}
const struct zcomp_ops backend_842 = {
.compress = compress_842,
.decompress = decompress_842,
.create_ctx = create_842,
.destroy_ctx = destroy_842,
.name = "842",
};
|