scompress.c (cf40a76e7d5874bb25f4404eecc58a2e033af885) | scompress.c (8cd579d2794b90f810e534e75783ba78cdc91a07) |
---|---|
1/* 2 * Synchronous Compression operations 3 * 4 * Copyright 2015 LG Electronics Inc. 5 * Copyright (c) 2016, Intel Corporation 6 * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 126 unchanged lines hidden (view full) --- 135 136 mutex_lock(&scomp_lock); 137 ret = crypto_scomp_alloc_all_scratches(); 138 mutex_unlock(&scomp_lock); 139 140 return ret; 141} 142 | 1/* 2 * Synchronous Compression operations 3 * 4 * Copyright 2015 LG Electronics Inc. 5 * Copyright (c) 2016, Intel Corporation 6 * Author: Giovanni Cabiddu <giovanni.cabiddu@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 126 unchanged lines hidden (view full) --- 135 136 mutex_lock(&scomp_lock); 137 ret = crypto_scomp_alloc_all_scratches(); 138 mutex_unlock(&scomp_lock); 139 140 return ret; 141} 142 |
143static void crypto_scomp_sg_free(struct scatterlist *sgl) 144{ 145 int i, n; 146 struct page *page; 147 148 if (!sgl) 149 return; 150 151 n = sg_nents(sgl); 152 for_each_sg(sgl, sgl, n, i) { 153 page = sg_page(sgl); 154 if (page) 155 __free_page(page); 156 } 157 158 kfree(sgl); 159} 160 161static struct scatterlist *crypto_scomp_sg_alloc(size_t size, gfp_t gfp) 162{ 163 struct scatterlist *sgl; 164 struct page *page; 165 int i, n; 166 167 n = ((size - 1) >> PAGE_SHIFT) + 1; 168 169 sgl = kmalloc_array(n, sizeof(struct scatterlist), gfp); 170 if (!sgl) 171 return NULL; 172 173 sg_init_table(sgl, n); 174 175 for (i = 0; i < n; i++) { 176 page = alloc_page(gfp); 177 if (!page) 178 goto err; 179 sg_set_page(sgl + i, page, PAGE_SIZE, 0); 180 } 181 182 return sgl; 183 184err: 185 sg_mark_end(sgl + i); 186 crypto_scomp_sg_free(sgl); 187 return NULL; 188} 189 | |
190static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) 191{ 192 struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); 193 void **tfm_ctx = acomp_tfm_ctx(tfm); 194 struct crypto_scomp *scomp = *tfm_ctx; 195 void **ctx = acomp_request_ctx(req); 196 const int cpu = get_cpu(); 197 u8 *scratch_src = *per_cpu_ptr(scomp_src_scratches, cpu); --- 17 unchanged lines hidden (view full) --- 215 if (dir) 216 ret = crypto_scomp_compress(scomp, scratch_src, req->slen, 217 scratch_dst, &req->dlen, *ctx); 218 else 219 ret = crypto_scomp_decompress(scomp, scratch_src, req->slen, 220 scratch_dst, &req->dlen, *ctx); 221 if (!ret) { 222 if (!req->dst) { | 143static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) 144{ 145 struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); 146 void **tfm_ctx = acomp_tfm_ctx(tfm); 147 struct crypto_scomp *scomp = *tfm_ctx; 148 void **ctx = acomp_request_ctx(req); 149 const int cpu = get_cpu(); 150 u8 *scratch_src = *per_cpu_ptr(scomp_src_scratches, cpu); --- 17 unchanged lines hidden (view full) --- 168 if (dir) 169 ret = crypto_scomp_compress(scomp, scratch_src, req->slen, 170 scratch_dst, &req->dlen, *ctx); 171 else 172 ret = crypto_scomp_decompress(scomp, scratch_src, req->slen, 173 scratch_dst, &req->dlen, *ctx); 174 if (!ret) { 175 if (!req->dst) { |
223 req->dst = crypto_scomp_sg_alloc(req->dlen, GFP_ATOMIC); | 176 req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL); |
224 if (!req->dst) 225 goto out; 226 } 227 scatterwalk_map_and_copy(scratch_dst, req->dst, 0, req->dlen, 228 1); 229 } 230out: 231 put_cpu(); --- 37 unchanged lines hidden (view full) --- 269 return PTR_ERR(scomp); 270 } 271 272 *ctx = scomp; 273 tfm->exit = crypto_exit_scomp_ops_async; 274 275 crt->compress = scomp_acomp_compress; 276 crt->decompress = scomp_acomp_decompress; | 177 if (!req->dst) 178 goto out; 179 } 180 scatterwalk_map_and_copy(scratch_dst, req->dst, 0, req->dlen, 181 1); 182 } 183out: 184 put_cpu(); --- 37 unchanged lines hidden (view full) --- 222 return PTR_ERR(scomp); 223 } 224 225 *ctx = scomp; 226 tfm->exit = crypto_exit_scomp_ops_async; 227 228 crt->compress = scomp_acomp_compress; 229 crt->decompress = scomp_acomp_decompress; |
277 crt->dst_free = crypto_scomp_sg_free; | 230 crt->dst_free = sgl_free; |
278 crt->reqsize = sizeof(void *); 279 280 return 0; 281} 282 283struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req) 284{ 285 struct crypto_acomp *acomp = crypto_acomp_reqtfm(req); --- 90 unchanged lines hidden --- | 231 crt->reqsize = sizeof(void *); 232 233 return 0; 234} 235 236struct acomp_req *crypto_acomp_scomp_alloc_ctx(struct acomp_req *req) 237{ 238 struct crypto_acomp *acomp = crypto_acomp_reqtfm(req); --- 90 unchanged lines hidden --- |