zcomp.c (52c7b4e2ba508a924c991e681db534e66a851adf) | zcomp.c (6a81bdfeb35094c3097650306a5fda9a990d8a97) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2 3#include <linux/kernel.h> 4#include <linux/string.h> 5#include <linux/err.h> 6#include <linux/slab.h> 7#include <linux/wait.h> 8#include <linux/sched.h> --- 31 unchanged lines hidden (view full) --- 40#if IS_ENABLED(CONFIG_ZRAM_BACKEND_842) 41 &backend_842, 42#endif 43 NULL 44}; 45 46static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) 47{ | 1// SPDX-License-Identifier: GPL-2.0-or-later 2 3#include <linux/kernel.h> 4#include <linux/string.h> 5#include <linux/err.h> 6#include <linux/slab.h> 7#include <linux/wait.h> 8#include <linux/sched.h> --- 31 unchanged lines hidden (view full) --- 40#if IS_ENABLED(CONFIG_ZRAM_BACKEND_842) 41 &backend_842, 42#endif 43 NULL 44}; 45 46static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) 47{ |
48 if (zstrm->ctx) 49 comp->ops->destroy_ctx(zstrm->ctx); | 48 comp->ops->destroy_ctx(&zstrm->ctx); |
50 vfree(zstrm->buffer); | 49 vfree(zstrm->buffer); |
51 zstrm->ctx = NULL; | |
52 zstrm->buffer = NULL; 53} 54 55static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) 56{ | 50 zstrm->buffer = NULL; 51} 52 53static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) 54{ |
57 zstrm->ctx = comp->ops->create_ctx(comp->params); | 55 int ret; |
58 | 56 |
57 ret = comp->ops->create_ctx(comp->params, &zstrm->ctx); 58 if (ret) 59 return ret; 60 |
|
59 /* 60 * allocate 2 pages. 1 for compressed data, plus 1 extra for the 61 * case when compressed size is larger than the original one 62 */ 63 zstrm->buffer = vzalloc(2 * PAGE_SIZE); | 61 /* 62 * allocate 2 pages. 1 for compressed data, plus 1 extra for the 63 * case when compressed size is larger than the original one 64 */ 65 zstrm->buffer = vzalloc(2 * PAGE_SIZE); |
64 if (!zstrm->ctx || !zstrm->buffer) { | 66 if (!zstrm->buffer) { |
65 zcomp_strm_free(comp, zstrm); 66 return -ENOMEM; 67 } 68 return 0; 69} 70 71static const struct zcomp_ops *lookup_backend_ops(const char *comp) 72{ --- 49 unchanged lines hidden (view full) --- 122 struct zcomp_req req = { 123 .src = src, 124 .dst = zstrm->buffer, 125 .src_len = PAGE_SIZE, 126 .dst_len = 2 * PAGE_SIZE, 127 }; 128 int ret; 129 | 67 zcomp_strm_free(comp, zstrm); 68 return -ENOMEM; 69 } 70 return 0; 71} 72 73static const struct zcomp_ops *lookup_backend_ops(const char *comp) 74{ --- 49 unchanged lines hidden (view full) --- 124 struct zcomp_req req = { 125 .src = src, 126 .dst = zstrm->buffer, 127 .src_len = PAGE_SIZE, 128 .dst_len = 2 * PAGE_SIZE, 129 }; 130 int ret; 131 |
130 ret = comp->ops->compress(zstrm->ctx, &req); | 132 ret = comp->ops->compress(&zstrm->ctx, &req); |
131 if (!ret) 132 *dst_len = req.dst_len; 133 return ret; 134} 135 136int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, 137 const void *src, unsigned int src_len, void *dst) 138{ 139 struct zcomp_req req = { 140 .src = src, 141 .dst = dst, 142 .src_len = src_len, 143 .dst_len = PAGE_SIZE, 144 }; 145 | 133 if (!ret) 134 *dst_len = req.dst_len; 135 return ret; 136} 137 138int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, 139 const void *src, unsigned int src_len, void *dst) 140{ 141 struct zcomp_req req = { 142 .src = src, 143 .dst = dst, 144 .src_len = src_len, 145 .dst_len = PAGE_SIZE, 146 }; 147 |
146 return comp->ops->decompress(zstrm->ctx, &req); | 148 return comp->ops->decompress(&zstrm->ctx, &req); |
147} 148 149int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) 150{ 151 struct zcomp *comp = hlist_entry(node, struct zcomp, node); 152 struct zcomp_strm *zstrm; 153 int ret; 154 --- 75 unchanged lines hidden --- | 149} 150 151int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) 152{ 153 struct zcomp *comp = hlist_entry(node, struct zcomp, node); 154 struct zcomp_strm *zstrm; 155 int ret; 156 --- 75 unchanged lines hidden --- |