This is a more general approach: for some backends, some of the data needed to create a context can be stored in zcomp structure. And we also can get zcomp_params structure from zcomp. Signed-off-by: Alexey Romanov <avromanov@xxxxxxxxxxxxxxxxx> --- drivers/block/zram/backend_842.c | 2 +- drivers/block/zram/backend_deflate.c | 3 ++- drivers/block/zram/backend_lz4.c | 3 ++- drivers/block/zram/backend_lz4hc.c | 3 ++- drivers/block/zram/backend_lzo.c | 2 +- drivers/block/zram/backend_lzorle.c | 2 +- drivers/block/zram/backend_zstd.c | 3 ++- drivers/block/zram/zcomp.c | 2 +- drivers/block/zram/zcomp.h | 4 +++- 9 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/block/zram/backend_842.c b/drivers/block/zram/backend_842.c index 10d9d5c60f53..9147feb1e994 100644 --- a/drivers/block/zram/backend_842.c +++ b/drivers/block/zram/backend_842.c @@ -21,7 +21,7 @@ static void destroy_842(struct zcomp_ctx *ctx) kfree(ctx->context); } -static int create_842(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int create_842(struct zcomp *zcomp, struct zcomp_ctx *ctx) { ctx->context = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); if (!ctx->context) diff --git a/drivers/block/zram/backend_deflate.c b/drivers/block/zram/backend_deflate.c index 0f7f252c12f4..10fde82dc5e7 100644 --- a/drivers/block/zram/backend_deflate.c +++ b/drivers/block/zram/backend_deflate.c @@ -46,8 +46,9 @@ static void deflate_destroy(struct zcomp_ctx *ctx) kfree(zctx); } -static int deflate_create(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int deflate_create(struct zcomp *zcomp, struct zcomp_ctx *ctx) { + struct zcomp_params *params = zcomp->params; struct deflate_ctx *zctx; size_t sz; int ret; diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c index 847f3334eb38..8f7c8f16b6ce 100644 --- a/drivers/block/zram/backend_lz4.c +++ b/drivers/block/zram/backend_lz4.c @@ -37,8 +37,9 @@ static void lz4_destroy(struct zcomp_ctx *ctx) kfree(zctx); } -static int lz4_create(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int lz4_create(struct zcomp *zcomp, struct zcomp_ctx *ctx) { + struct zcomp_params *params = zcomp->params; struct lz4_ctx *zctx; zctx = kzalloc(sizeof(*zctx), GFP_KERNEL); diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c index 5f37d5abcaeb..b0302b8027ab 100644 --- a/drivers/block/zram/backend_lz4hc.c +++ b/drivers/block/zram/backend_lz4hc.c @@ -37,8 +37,9 @@ static void lz4hc_destroy(struct zcomp_ctx *ctx) kfree(zctx); } -static int lz4hc_create(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int lz4hc_create(struct zcomp *zcomp, struct zcomp_ctx *ctx) { + struct zcomp_params *params = zcomp->params; struct lz4hc_ctx *zctx; zctx = kzalloc(sizeof(*zctx), GFP_KERNEL); diff --git a/drivers/block/zram/backend_lzo.c b/drivers/block/zram/backend_lzo.c index 4c906beaae6b..78e611ea841e 100644 --- a/drivers/block/zram/backend_lzo.c +++ b/drivers/block/zram/backend_lzo.c @@ -15,7 +15,7 @@ static int lzo_setup_params(struct zcomp_params *params) return 0; } -static int lzo_create(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int lzo_create(struct zcomp *params, struct zcomp_ctx *ctx) { ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); if (!ctx->context) diff --git a/drivers/block/zram/backend_lzorle.c b/drivers/block/zram/backend_lzorle.c index 10640c96cbfc..b0ff72468ea8 100644 --- a/drivers/block/zram/backend_lzorle.c +++ b/drivers/block/zram/backend_lzorle.c @@ -15,7 +15,7 @@ static int lzorle_setup_params(struct zcomp_params *params) return 0; } -static int lzorle_create(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int lzorle_create(struct zcomp *zcomp, struct zcomp_ctx *ctx) { ctx->context = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); if (!ctx->context) diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend_zstd.c index 1184c0036f44..b73b975599f4 100644 --- a/drivers/block/zram/backend_zstd.c +++ b/drivers/block/zram/backend_zstd.c @@ -125,8 +125,9 @@ static void zstd_destroy(struct zcomp_ctx *ctx) kfree(zctx); } -static int zstd_create(struct zcomp_params *params, struct zcomp_ctx *ctx) +static int zstd_create(struct zcomp *zcomp, struct zcomp_ctx *ctx) { + struct zcomp_params *params = zcomp->params; struct zstd_ctx *zctx; zstd_parameters prm; size_t sz; diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index bb514403e305..be3a31f09344 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -54,7 +54,7 @@ static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) { int ret; - ret = comp->ops->create_ctx(comp->params, &zstrm->ctx); + ret = comp->ops->create_ctx(comp, &zstrm->ctx); if (ret) return ret; diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index ad5762813842..89d32bb13f8c 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -45,13 +45,15 @@ struct zcomp_req { size_t dst_len; }; +struct zcomp; + struct zcomp_ops { int (*compress)(struct zcomp_params *params, struct zcomp_ctx *ctx, struct zcomp_req *req); int (*decompress)(struct zcomp_params *params, struct zcomp_ctx *ctx, struct zcomp_req *req); - int (*create_ctx)(struct zcomp_params *params, struct zcomp_ctx *ctx); + int (*create_ctx)(struct zcomp *zcomp, struct zcomp_ctx *ctx); void (*destroy_ctx)(struct zcomp_ctx *ctx); int (*setup_params)(struct zcomp_params *params); -- 2.34.1