Re: [PATCH] pstore: use crypto compress API
From: Kees Cook
Date: Fri Mar 09 2018 - 17:01:05 EST
On Fri, Mar 9, 2018 at 2:51 AM, Geliang Tang <geliangtang@xxxxxxxxx> wrote:
> In the pstore compression part, we use zlib/lzo/lz4/lz4hc/842
> compression algorithm API to implement pstore compression backends. But
> there are many repeat codes in these implementations. This patch uses
> crypto compress API to simplify these codes.
>
> 1) rewrite allocate_buf_for_compression, free_buf_for_compression,
> pstore_compress, pstore_decompress functions using crypto compress API.
> 2) drop compress, decompress, allocate, free functions in pstore_zbackend,
> and add zbufsize function to get each different compress buffer size.
> 3) use late_initcall to call ramoops_init later, to make sure the crypto
> subsystem has already initialized.
> 4) use 'unsigned int' type instead of 'size_t' in pstore_compress,
> pstore_decompress functions' length arguments.
> 5) rename 'zlib' to 'deflate' to follow the crypto API's name
> convention.
>
> Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx>
> ---
> fs/pstore/Kconfig | 33 ++--
> fs/pstore/platform.c | 413 ++++++++-------------------------------------------
> fs/pstore/ram.c | 2 +-
> 3 files changed, 80 insertions(+), 368 deletions(-)
Yay code removal! This is very nice. Thanks!
-Kees
--
Kees Cook
Pixel Security<div class="gmail_extra"><br><div class="gmail_quote">On
Fri, Mar 9, 2018 at 2:51 AM, Geliang Tang <span dir="ltr"><<a
href="mailto:geliangtang@xxxxxxxxx"
target="_blank">geliangtang@xxxxxxxxx</a>></span>
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">In the pstore
compression part, we use zlib/lzo/lz4/lz4hc/842<br>
compression algorithm API to implement pstore compression backends. But<br>
there are many repeat codes in these implementations. This patch uses<br>
crypto compress API to simplify these codes.<br>
<br>
1) rewrite allocate_buf_for_compression, free_buf_for_compression,<br>
pstore_compress, pstore_decompress functions using crypto compress API.<br>
2) drop compress, decompress, allocate, free functions in pstore_zbackend,<br>
and add zbufsize function to get each different compress buffer size.<br>
3) use late_initcall to call ramoops_init later, to make sure the crypto<br>
subsystem has already initialized.<br>
4) use 'unsigned int' type instead of 'size_t' in pstore_compress,<br>
pstore_decompress functions' length arguments.<br>
5) rename 'zlib' to 'deflate' to follow the crypto API's name<br>
convention.<br>
<br>
Signed-off-by: Geliang Tang <<a
href="mailto:geliangtang@xxxxxxxxx">geliangtang@xxxxxxxxx</a>><br>
---<br>
fs/pstore/Kconfig | 33 ++--<br>
fs/pstore/platform.c | 413
++++++++----------------------<wbr>---------------------<br>
fs/pstore/ram.c | 2 +-<br>
3 files changed, 80 insertions(+), 368 deletions(-)<br>
<br>
diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig<br>
index e4e22026c7a1..26f1c0fcada3 100644<br>
--- a/fs/pstore/Kconfig<br>
+++ b/fs/pstore/Kconfig<br>
@@ -12,51 +12,46 @@ config PSTORE<br>
If you don't have a platform
persistent store driver,<br>
say N.<br>
<br>
-config PSTORE_ZLIB_COMPRESS<br>
- bool "ZLIB compression"<br>
+config PSTORE_DEFLATE_COMPRESS<br>
+ bool "DEFLATE compression"<br>
default y<br>
depends on PSTORE<br>
- select ZLIB_DEFLATE<br>
- select ZLIB_INFLATE<br>
+ select CRYPTO_DEFLATE<br>
help<br>
- This option enables ZLIB
compression algorithm support.<br>
+ This option enables DEFLATE
compression algorithm support.<br>
<br>
config PSTORE_LZO_COMPRESS<br>
bool "LZO compression"<br>
depends on PSTORE<br>
- select LZO_COMPRESS<br>
- select LZO_DECOMPRESS<br>
+ select CRYPTO_LZO<br>
help<br>
This option enables LZO compression
algorithm support.<br>
<br>
config PSTORE_LZ4_COMPRESS<br>
bool "LZ4 compression"<br>
depends on PSTORE<br>
- select LZ4_COMPRESS<br>
- select LZ4_DECOMPRESS<br>
+ select CRYPTO_LZ4<br>
help<br>
This option enables LZ4 compression
algorithm support.<br>
<br>
config PSTORE_LZ4HC_COMPRESS<br>
bool "LZ4HC compression"<br>
depends on PSTORE<br>
- select LZ4HC_COMPRESS<br>
- select LZ4_DECOMPRESS<br>
+ select CRYPTO_LZ4HC<br>
help<br>
This option enables LZ4HC (high
compression) mode algorithm.<br>
<br>
config PSTORE_842_COMPRESS<br>
bool "842 compression"<br>
depends on PSTORE<br>
- select 842_COMPRESS<br>
- select 842_DECOMPRESS<br>
+ select CRYPTO_842<br>
help<br>
This option enables 842 compression
algorithm support.<br>
<br>
config PSTORE_COMPRESS<br>
def_bool y<br>
depends on PSTORE<br>
- depends on PSTORE_ZLIB_COMPRESS ||
PSTORE_LZO_COMPRESS || \<br>
+ depends on PSTORE_DEFLATE_COMPRESS ||
PSTORE_LZO_COMPRESS || \<br>
PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS ||
\<br>
PSTORE_842_COMPRESS<br>
<br>
@@ -69,12 +64,12 @@ choice<br>
the kernel command line.<br>
<br>
Currently, pstore has support for 5
compression algorithms:<br>
- zlib, lzo, lz4, lz4hc and 842.<br>
+ deflate, lzo, lz4, lz4hc and 842.<br>
<br>
- The default compression algorithm
is zlib.<br>
+ The default compression algorithm
is deflate.<br>
<br>
- config PSTORE_ZLIB_COMPRESS_DEFAULT<br>
- bool "zlib" if
PSTORE_ZLIB_COMPRESS=y<br>
+ config PSTORE_DEFLATE_COMPRESS_<wbr>DEFAULT<br>
+ bool "deflate"
if PSTORE_DEFLATE_COMPRESS=y<br>
<br>
config PSTORE_LZO_COMPRESS_DEFAULT<br>
bool "lzo" if
PSTORE_LZO_COMPRESS=y<br>
@@ -93,7 +88,7 @@ endchoice<br>
config PSTORE_COMPRESS_DEFAULT<br>
string<br>
depends on PSTORE_COMPRESS<br>
- default "zlib" if PSTORE_ZLIB_COMPRESS_DEFAULT<br>
+ default "deflate" if
PSTORE_DEFLATE_COMPRESS_<wbr>DEFAULT<br>
default "lzo" if PSTORE_LZO_COMPRESS_DEFAULT<br>
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT<br>
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT<br>
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c<br>
index 06e3b280c3a5..1d40b4588d68 100644<br>
--- a/fs/pstore/platform.c<br>
+++ b/fs/pstore/platform.c<br>
@@ -28,18 +28,13 @@<br>
#include <linux/console.h><br>
#include <linux/module.h><br>
#include <linux/pstore.h><br>
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS<br>
-#include <linux/zlib.h><br>
-#endif<br>
#ifdef CONFIG_PSTORE_LZO_COMPRESS<br>
#include <linux/lzo.h><br>
#endif<br>
#if defined(CONFIG_PSTORE_LZ4_<wbr>COMPRESS) ||
defined(CONFIG_PSTORE_LZ4HC_<wbr>COMPRESS)<br>
#include <linux/lz4.h><br>
#endif<br>
-#ifdef CONFIG_PSTORE_842_COMPRESS<br>
-#include <linux/sw842.h><br>
-#endif<br>
+#include <linux/crypto.h><br>
#include <linux/string.h><br>
#include <linux/timer.h><br>
#include <linux/slab.h><br>
@@ -85,25 +80,10 @@ static char *compress =<br>
#endif<br>
<br>
/* Compression parameters */<br>
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS<br>
-#define COMPR_LEVEL 6<br>
-#define WINDOW_BITS 12<br>
-#define MEM_LEVEL 4<br>
-static struct z_stream_s stream;<br>
-#endif<br>
-#if defined(CONFIG_PSTORE_LZO_<wbr>COMPRESS) || \<br>
- defined(CONFIG_PSTORE_LZ4_<wbr>COMPRESS) || \<br>
- defined(CONFIG_PSTORE_LZ4HC_<wbr>COMPRESS) || \<br>
- defined(CONFIG_PSTORE_842_<wbr>COMPRESS)<br>
-static unsigned char *workspace;<br>
-#endif<br>
+static struct crypto_comp *tfm;<br>
<br>
struct pstore_zbackend {<br>
- int (*compress)(const void *in, void *out,
size_t inlen, size_t outlen);<br>
- int (*decompress)(void *in, void *out,
size_t inlen, size_t outlen);<br>
- void (*allocate)(void);<br>
- void (*free)(void);<br>
-<br>
+ int (*zbufsize)(size_t size);<br>
const char *name;<br>
};<br>
<br>
@@ -162,77 +142,12 @@ bool pstore_cannot_block_path(enum
kmsg_dump_reason reason)<br>
}<br>
EXPORT_SYMBOL_GPL(pstore_<wbr>cannot_block_path);<br>
<br>
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS<br>
-/* Derived from logfs_compress() */<br>
-static int compress_zlib(const void *in, void *out, size_t inlen,
size_t outlen)<br>
+#ifdef CONFIG_PSTORE_DEFLATE_COMPRESS<br>
+static int zbufsize_deflate(size_t size)<br>
{<br>
- int err, ret;<br>
-<br>
- ret = -EIO;<br>
- err = zlib_deflateInit2(&stream,
COMPR_LEVEL, Z_DEFLATED, WINDOW_BITS,<br>
-
MEM_LEVEL, Z_DEFAULT_STRATEGY);<br>
- if (err != Z_OK)<br>
- goto error;<br>
-<br>
- stream.next_in = in;<br>
- stream.avail_in = inlen;<br>
- stream.total_in = 0;<br>
- stream.next_out = out;<br>
- stream.avail_out = outlen;<br>
- stream.total_out = 0;<br>
-<br>
- err = zlib_deflate(&stream, Z_FINISH);<br>
- if (err != Z_STREAM_END)<br>
- goto error;<br>
-<br>
- err = zlib_deflateEnd(&stream);<br>
- if (err != Z_OK)<br>
- goto error;<br>
-<br>
- if (stream.total_out >= stream.total_in)<br>
- goto error;<br>
-<br>
- ret = stream.total_out;<br>
-error:<br>
- return ret;<br>
-}<br>
-<br>
-/* Derived from logfs_uncompress */<br>
-static int decompress_zlib(void *in, void *out, size_t inlen, size_t
outlen)<br>
-{<br>
- int err, ret;<br>
-<br>
- ret = -EIO;<br>
- err = zlib_inflateInit2(&stream,
WINDOW_BITS);<br>
- if (err != Z_OK)<br>
- goto error;<br>
-<br>
- stream.next_in = in;<br>
- stream.avail_in = inlen;<br>
- stream.total_in = 0;<br>
- stream.next_out = out;<br>
- stream.avail_out = outlen;<br>
- stream.total_out = 0;<br>
-<br>
- err = zlib_inflate(&stream, Z_FINISH);<br>
- if (err != Z_STREAM_END)<br>
- goto error;<br>
-<br>
- err = zlib_inflateEnd(&stream);<br>
- if (err != Z_OK)<br>
- goto error;<br>
-<br>
- ret = stream.total_out;<br>
-error:<br>
- return ret;<br>
-}<br>
-<br>
-static void allocate_zlib(void)<br>
-{<br>
- size_t size;<br>
size_t cmpr;<br>
<br>
- switch (psinfo->bufsize) {<br>
+ switch (size) {<br>
/* buffer range for efivars */<br>
case 1000 ... 2000:<br>
cmpr = 56;<br>
@@ -252,287 +167,61 @@ static void allocate_zlib(void)<br>
break;<br>
}<br>
<br>
- big_oops_buf_sz = (psinfo->bufsize *
100) / cmpr;<br>
- big_oops_buf = kmalloc(big_oops_buf_sz,
GFP_KERNEL);<br>
- if (big_oops_buf) {<br>
- size =
max(zlib_deflate_<wbr>workspacesize(WINDOW_BITS, MEM_LEVEL),<br>
-
zlib_inflate_workspacesize());<br>
-
stream.workspace = kmalloc(size, GFP_KERNEL);<br>
- if
(!stream.workspace) {<br>
-
pr_err("No memory for compression workspace; skipping
compression\n");<br>
-
kfree(big_oops_buf);<br>
-
big_oops_buf = NULL;<br>
- }<br>
- } else {<br>
- pr_err("No
memory for uncompressed data; skipping compression\n");<br>
-
stream.workspace = NULL;<br>
- }<br>
-<br>
-}<br>
-<br>
-static void free_zlib(void)<br>
-{<br>
- kfree(stream.workspace);<br>
- stream.workspace = NULL;<br>
- kfree(big_oops_buf);<br>
- big_oops_buf = NULL;<br>
- big_oops_buf_sz = 0;<br>
+ return (size * 100) / cmpr;<br>
}<br>
#endif<br>
<br>
#ifdef CONFIG_PSTORE_LZO_COMPRESS<br>
-static int compress_lzo(const void *in, void *out, size_t inlen,
size_t outlen)<br>
+static int zbufsize_lzo(size_t size)<br>
{<br>
- int ret;<br>
-<br>
- ret = lzo1x_1_compress(in, inlen, out,
&outlen, workspace);<br>
- if (ret != LZO_E_OK) {<br>
-
pr_err("lzo_compress error, ret = %d!\n", ret);<br>
- return -EIO;<br>
- }<br>
-<br>
- return outlen;<br>
-}<br>
-<br>
-static int decompress_lzo(void *in, void *out, size_t inlen, size_t outlen)<br>
-{<br>
- int ret;<br>
-<br>
- ret = lzo1x_decompress_safe(in, inlen,
out, &outlen);<br>
- if (ret != LZO_E_OK) {<br>
-
pr_err("lzo_decompress error, ret = %d!\n", ret);<br>
- return -EIO;<br>
- }<br>
-<br>
- return outlen;<br>
-}<br>
-<br>
-static void allocate_lzo(void)<br>
-{<br>
- big_oops_buf_sz =
lzo1x_worst_compress(psinfo-><wbr>bufsize);<br>
- big_oops_buf = kmalloc(big_oops_buf_sz,
GFP_KERNEL);<br>
- if (big_oops_buf) {<br>
- workspace =
kmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);<br>
- if (!workspace) {<br>
-
pr_err("No memory for compression workspace; skipping
compression\n");<br>
-
kfree(big_oops_buf);<br>
-
big_oops_buf = NULL;<br>
- }<br>
- } else {<br>
- pr_err("No
memory for uncompressed data; skipping compression\n");<br>
- workspace = NULL;<br>
- }<br>
-}<br>
-<br>
-static void free_lzo(void)<br>
-{<br>
- kfree(workspace);<br>
- kfree(big_oops_buf);<br>
- big_oops_buf = NULL;<br>
- big_oops_buf_sz = 0;<br>
+ return lzo1x_worst_compress(size);<br>
}<br>
#endif<br>
<br>
#if defined(CONFIG_PSTORE_LZ4_<wbr>COMPRESS) ||
defined(CONFIG_PSTORE_LZ4HC_<wbr>COMPRESS)<br>
-static int decompress_lz4(void *in, void *out, size_t inlen, size_t outlen)<br>
-{<br>
- int ret;<br>
-<br>
- ret = LZ4_decompress_safe(in, out, inlen,
outlen);<br>
- if (ret < 0) {<br>
- /*<br>
- *
LZ4_decompress_safe will return an error code<br>
- * (< 0) if
decompression failed<br>
- */<br>
-
pr_err("LZ4_decompress_safe error, ret = %d!\n", ret);<br>
- return -EIO;<br>
- }<br>
-<br>
- return ret;<br>
-}<br>
-<br>
-static void free_lz4(void)<br>
-{<br>
- kfree(workspace);<br>
- kfree(big_oops_buf);<br>
- big_oops_buf = NULL;<br>
- big_oops_buf_sz = 0;<br>
-}<br>
-#endif<br>
-<br>
-#ifdef CONFIG_PSTORE_LZ4_COMPRESS<br>
-static int compress_lz4(const void *in, void *out, size_t inlen,
size_t outlen)<br>
-{<br>
- int ret;<br>
-<br>
- ret = LZ4_compress_default(in, out, inlen,
outlen, workspace);<br>
- if (!ret) {<br>
-
pr_err("LZ4_compress_default error; compression failed!\n");<br>
- return -EIO;<br>
- }<br>
-<br>
- return ret;<br>
-}<br>
-<br>
-static void allocate_lz4(void)<br>
-{<br>
- big_oops_buf_sz =
LZ4_compressBound(psinfo-><wbr>bufsize);<br>
- big_oops_buf = kmalloc(big_oops_buf_sz,
GFP_KERNEL);<br>
- if (big_oops_buf) {<br>
- workspace =
kmalloc(LZ4_MEM_COMPRESS, GFP_KERNEL);<br>
- if (!workspace) {<br>
-
pr_err("No memory for compression workspace; skipping
compression\n");<br>
-
kfree(big_oops_buf);<br>
-
big_oops_buf = NULL;<br>
- }<br>
- } else {<br>
- pr_err("No
memory for uncompressed data; skipping compression\n");<br>
- workspace = NULL;<br>
- }<br>
-}<br>
-#endif<br>
-<br>
-#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS<br>
-static int compress_lz4hc(const void *in, void *out,<br>
-
size_t inlen, size_t outlen)<br>
+static int zbufsize_lz4(size_t size)<br>
{<br>
- int ret;<br>
-<br>
- ret = LZ4_compress_HC(in, out, inlen, outlen,<br>
-
LZ4HC_DEFAULT_CLEVEL,
workspace);<br>
- if (!ret) {<br>
-
pr_err("LZ4_compress_HC error; compression failed!\n");<br>
- return -EIO;<br>
- }<br>
-<br>
- return ret;<br>
-}<br>
-<br>
-static void allocate_lz4hc(void)<br>
-{<br>
- big_oops_buf_sz =
LZ4_compressBound(psinfo-><wbr>bufsize);<br>
- big_oops_buf = kmalloc(big_oops_buf_sz,
GFP_KERNEL);<br>
- if (big_oops_buf) {<br>
- workspace =
kmalloc(LZ4HC_MEM_COMPRESS, GFP_KERNEL);<br>
- if (!workspace) {<br>
-
pr_err("No memory for compression workspace; skipping
compression\n");<br>
-
kfree(big_oops_buf);<br>
-
big_oops_buf = NULL;<br>
- }<br>
- } else {<br>
- pr_err("No
memory for uncompressed data; skipping compression\n");<br>
- workspace = NULL;<br>
- }<br>
+ return LZ4_compressBound(size);<br>
}<br>
#endif<br>
<br>
#ifdef CONFIG_PSTORE_842_COMPRESS<br>
-static int compress_842(const void *in, void *out, size_t inlen,
size_t outlen)<br>
-{<br>
- int ret;<br>
- unsigned int size;<br>
-<br>
- if (outlen > UINT_MAX)<br>
- return -EIO;<br>
- size = outlen;<br>
-<br>
- ret = sw842_compress(in, inlen, out,
&size, workspace);<br>
- if (ret) {<br>
-
pr_err("sw842_compress error; compression failed!\n");<br>
- return ret;<br>
- }<br>
-<br>
- return size;<br>
-}<br>
-<br>
-static int decompress_842(void *in, void *out, size_t inlen, size_t outlen)<br>
+static int zbufsize_842(size_t size)<br>
{<br>
- int ret;<br>
- unsigned int size;<br>
-<br>
- if (outlen > UINT_MAX)<br>
- return -EIO;<br>
- size = outlen;<br>
-<br>
- ret = sw842_decompress(in, inlen, out,
&size);<br>
- if (ret) {<br>
-
pr_err("sw842_decompress error, ret = %d!\n", ret);<br>
- return ret;<br>
- }<br>
-<br>
return size;<br>
}<br>
-<br>
-static void allocate_842(void)<br>
-{<br>
- big_oops_buf_sz = psinfo->bufsize;<br>
- big_oops_buf = kmalloc(big_oops_buf_sz,
GFP_KERNEL);<br>
- if (big_oops_buf) {<br>
- workspace =
kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL);<br>
- if (!workspace) {<br>
-
kfree(big_oops_buf);<br>
-
big_oops_buf = NULL;<br>
- }<br>
- } else {<br>
- pr_err("No
memory for uncompressed data; skipping compression\n");<br>
- workspace = NULL;<br>
- }<br>
-}<br>
-<br>
-static void free_842(void)<br>
-{<br>
- kfree(workspace);<br>
- kfree(big_oops_buf);<br>
- big_oops_buf = NULL;<br>
- big_oops_buf_sz = 0;<br>
-}<br>
#endif<br>
<br>
static const struct pstore_zbackend *zbackend __ro_after_init;<br>
<br>
static const struct pstore_zbackend zbackends[] = {<br>
-#ifdef CONFIG_PSTORE_ZLIB_COMPRESS<br>
+#ifdef CONFIG_PSTORE_DEFLATE_COMPRESS<br>
{<br>
-
.compress = compress_zlib,<br>
-
.decompress = decompress_zlib,<br>
-
.allocate = allocate_zlib,<br>
- .free
= free_zlib,<br>
- .name
= "zlib",<br>
+
.zbufsize = zbufsize_deflate,<br>
+ .name
= "deflate",<br>
},<br>
#endif<br>
#ifdef CONFIG_PSTORE_LZO_COMPRESS<br>
{<br>
-
.compress = compress_lzo,<br>
-
.decompress = decompress_lzo,<br>
-
.allocate = allocate_lzo,<br>
- .free
= free_lzo,<br>
+
.zbufsize = zbufsize_lzo,<br>
.name
= "lzo",<br>
},<br>
#endif<br>
#ifdef CONFIG_PSTORE_LZ4_COMPRESS<br>
{<br>
-
.compress = compress_lz4,<br>
-
.decompress = decompress_lz4,<br>
-
.allocate = allocate_lz4,<br>
- .free
= free_lz4,<br>
+
.zbufsize = zbufsize_lz4,<br>
.name
= "lz4",<br>
},<br>
#endif<br>
#ifdef CONFIG_PSTORE_LZ4HC_COMPRESS<br>
{<br>
-
.compress = compress_lz4hc,<br>
-
.decompress = decompress_lz4,<br>
-
.allocate = allocate_lz4hc,<br>
- .free
= free_lz4,<br>
+
.zbufsize = zbufsize_lz4,<br>
.name
= "lz4hc",<br>
},<br>
#endif<br>
#ifdef CONFIG_PSTORE_842_COMPRESS<br>
{<br>
-
.compress = compress_842,<br>
-
.decompress = decompress_842,<br>
-
.allocate = allocate_842,<br>
- .free
= free_842,<br>
+
.zbufsize = zbufsize_842,<br>
.name
= "842",<br>
},<br>
#endif<br>
@@ -540,37 +229,65 @@ static const struct pstore_zbackend zbackends[] = {<br>
};<br>
<br>
static int pstore_compress(const void *in, void *out,<br>
-
size_t inlen, size_t outlen)<br>
+
unsigned int inlen, unsigned int outlen)<br>
{<br>
- if (zbackend)<br>
- return
zbackend->compress(in, out, inlen, outlen);<br>
- else<br>
- return -EIO;<br>
+ int ret;<br>
+<br>
+ ret = crypto_comp_compress(tfm, in, inlen,
out, &outlen);<br>
+ if (ret) {<br>
+
pr_err("crypto_comp_compress failed, ret = %d!\n", ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ return outlen;<br>
}<br>
<br>
-static int pstore_decompress(void *in, void *out, size_t inlen,
size_t outlen)<br>
+static int pstore_decompress(void *in, void *out,<br>
+
unsigned int inlen, unsigned int
outlen)<br>
{<br>
- if (zbackend)<br>
- return
zbackend->decompress(in, out, inlen, outlen);<br>
- else<br>
- return -EIO;<br>
+ int ret;<br>
+<br>
+ ret = crypto_comp_decompress(tfm, in,
inlen, out, &outlen);<br>
+ if (ret) {<br>
+
pr_err("crypto_comp_decompress failed, ret = %d!\n", ret);<br>
+ return ret;<br>
+ }<br>
+<br>
+ return outlen;<br>
}<br>
<br>
static void allocate_buf_for_compression(<wbr>void)<br>
{<br>
- if (zbackend) {<br>
-
zbackend->allocate();<br>
- } else {<br>
-
pr_err("allocate compression buffer error!\n");<br>
+ if (!zbackend)<br>
+ return;<br>
+<br>
+ if
(!crypto_has_comp(zbackend-><wbr>name, 0, 0)) {<br>
+ pr_err("No %s
compression\n", zbackend->name);<br>
+ return;<br>
+ }<br>
+<br>
+ big_oops_buf_sz =
zbackend->zbufsize(psinfo-><wbr>bufsize);<br>
+ if (big_oops_buf_sz <= 0)<br>
+ return;<br>
+<br>
+ big_oops_buf = kmalloc(big_oops_buf_sz,
GFP_KERNEL);<br>
+ if (!big_oops_buf)<br>
+ return;<br>
+<br>
+ tfm =
crypto_alloc_comp(zbackend-><wbr>name, 0, 0);<br>
+ if (IS_ERR_OR_NULL(tfm)) {<br>
+ kfree(big_oops_buf);<br>
+ big_oops_buf = NULL;<br>
}<br>
}<br>
<br>
static void free_buf_for_compression(void)<br>
{<br>
- if (zbackend)<br>
- zbackend->free();<br>
- else<br>
- pr_err("free
compression buffer error!\n");<br>
+ if (!IS_ERR_OR_NULL(tfm))<br>
+
crypto_free_comp(tfm);<br>
+ kfree(big_oops_buf);<br>
+ big_oops_buf = NULL;<br>
+ big_oops_buf_sz = 0;<br>
}<br>
<br>
/*<br>
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c<br>
index 7125b398d312..49b2bc114868 100644<br>
--- a/fs/pstore/ram.c<br>
+++ b/fs/pstore/ram.c<br>
@@ -938,7 +938,7 @@ static int __init ramoops_init(void)<br>
ramoops_register_dummy();<br>
return
platform_driver_register(&<wbr>ramoops_driver);<br>
}<br>
-postcore_initcall(ramoops_<wbr>init);<br>
+late_initcall(ramoops_init);<br>
<br>
static void __exit ramoops_exit(void)<br>
{<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.1<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>--
<br><div class="gmail_signature" data-smartmail="gmail_signature">Kees
Cook<br>Pixel Security</div>
</div>