summaryrefslogtreecommitdiffstats
path: root/drivers/block/zram/backend_lz4hc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/zram/backend_lz4hc.c')
-rw-r--r--drivers/block/zram/backend_lz4hc.c51
1 files changed, 20 insertions, 31 deletions
diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c
index 6da71ec5fc05..928a6ea78668 100644
--- a/drivers/block/zram/backend_lz4hc.c
+++ b/drivers/block/zram/backend_lz4hc.c
@@ -5,60 +5,47 @@
#include "backend_lz4hc.h"
-struct lz4hc_ctx {
- void *mem;
- s32 level;
-};
+static void lz4hc_release_params(struct zcomp_params *params)
+{
+}
-static void lz4hc_destroy(struct zcomp_ctx *ctx)
+static int lz4hc_setup_params(struct zcomp_params *params)
{
- struct lz4hc_ctx *zctx = ctx->context;
+ if (params->level == ZCOMP_PARAM_NO_LEVEL)
+ params->level = LZ4HC_DEFAULT_CLEVEL;
- if (!zctx)
- return;
+ return 0;
+}
- vfree(zctx->mem);
- kfree(zctx);
+static void lz4hc_destroy(struct zcomp_ctx *ctx)
+{
+ vfree(ctx->context);
}
static int lz4hc_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
{
- struct lz4hc_ctx *zctx;
-
- zctx = kzalloc(sizeof(*zctx), GFP_KERNEL);
- if (!zctx)
+ ctx->context = vmalloc(LZ4HC_MEM_COMPRESS);
+ if (!ctx->context)
return -ENOMEM;
- ctx->context = zctx;
- if (params->level != ZCOMP_PARAM_NO_LEVEL)
- zctx->level = params->level;
- else
- zctx->level = LZ4HC_DEFAULT_CLEVEL;
-
- zctx->mem = vmalloc(LZ4HC_MEM_COMPRESS);
- if (!zctx->mem)
- goto error;
-
return 0;
-error:
- lz4hc_destroy(ctx);
- return -EINVAL;
}
-static int lz4hc_compress(struct zcomp_ctx *ctx, struct zcomp_req *req)
+static int lz4hc_compress(struct zcomp_params *params, struct zcomp_ctx *ctx,
+ struct zcomp_req *req)
{
- struct lz4hc_ctx *zctx = ctx->context;
int ret;
ret = LZ4_compress_HC(req->src, req->dst, req->src_len, req->dst_len,
- zctx->level, zctx->mem);
+ params->level, ctx->context);
if (!ret)
return -EINVAL;
req->dst_len = ret;
return 0;
}
-static int lz4hc_decompress(struct zcomp_ctx *ctx, struct zcomp_req *req)
+static int lz4hc_decompress(struct zcomp_params *params, struct zcomp_ctx *ctx,
+ struct zcomp_req *req)
{
int ret;
@@ -74,5 +61,7 @@ const struct zcomp_ops backend_lz4hc = {
.decompress = lz4hc_decompress,
.create_ctx = lz4hc_create,
.destroy_ctx = lz4hc_destroy,
+ .setup_params = lz4hc_setup_params,
+ .release_params = lz4hc_release_params,
.name = "lz4hc",
};